日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Leonbao:MapKit学习笔记

發布時間:2025/4/16 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Leonbao:MapKit学习笔记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下僅作了解, 實際使用以百度地圖居多, 因為百度地圖有動態路徑規劃等接口

?

MapKit學習筆記 ??

原帖: http://www.cocoachina.com/bbs/read.php?tid-66687-fpage-6.html

1、概述
插入MapView,設置Delegate(一般為Controller),Annotations記錄興趣位置點(AnnotationView用來顯示興趣位置點),annotation是可選的,選中的annotation會顯示callout,用來顯示信息。

2、設置地圖顯示類型:
mapView.mapType = MKMapTypeStandard;
mapView.mapType = MKMapTypeSatellite;
mapView.mapType = MKMapTypeHybrid;?

3、顯示用戶位置
設置為可以顯示用戶位置:
mapView.showsUserLocation = YES;?
判斷用戶當前位置是否可見(只讀屬性):
userLocationVisible?

得到用戶位置坐標:當userLocationVisible為YES時
CLLocationCoordinate2D coords = mapView.userLocation.location.coordinate;?

4、坐標范圍
MKCoordinateRegion用來設置坐標顯示范圍。
包括兩部分:Center(CLLocationCoordinate2D?struct,包括latitude和longitude),坐標中心
和Span(MKCoordinateSpan?struct,包括latitudeDelta和longitudeDelta),縮放級別
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(center,2000, 2000);?
以上代碼創建一個以center為中心,上下各1000米,左右各1000米得區域,但其是一個矩形,不符合MapView的橫縱比例
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];?
以上代碼創建出來一個符合MapView橫縱比例的區域
[mapView setRegion:adjustedRegion animated:YES];?
以上代碼為:最終顯示該區域

5、Delegate
使用MapView須符合MKMapViewDelegate協議

5.1、地圖加載Delegate
當需要從Google服務器取得新地圖時
mapViewWillStartLoadingMap:?
當成功地取得地圖后
mapViewDidFinishLoadingMap:?
當取得地圖失敗后(建議至少要實現此方法)
mapViewDidFailLoadingMap:withError:?

5.2、范圍變化Delegate
當手勢開始(拖拽,放大,縮小,雙擊)
mapView:regionWillChangeAnimated:?
當手勢結束(拖拽,放大,縮小,雙擊)
mapView:regionDidChangeAnimated:?

判斷坐標是否在MapView顯示范圍內:
CLLocationDegrees leftDegrees = mapView.region.center.longitude –(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees rightDegrees = mapView.region.center.longitude +(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees bottomDegrees = mapView.region.center.latitude –(mapView.region.span.latitudeDelta / 2.0);
CLLocationDegrees topDegrees = self.region.center.latitude +(mapView.region.span.latitudeDelta / 2.0);

if (leftDegrees > rightDegrees) { // Int'l Date Line in View
leftDegrees = -180.0 - leftDegrees;
if (coords.longitude > 0) // coords to West of Date Line
coords.longitude = -180.0 - coords.longitude;
}
If (leftDegrees <= coords.longitude && coords.longitude <= rightDegrees &&?bottomDegrees <= coords.latitude && coords.latitude <= topDegrees) {
???
// 坐標在范圍內
}?

6、Annotation
Annotation包含兩部分:Annotation Object和Annotation View
Annotation Object必須符合協議MKAnnotation,包括兩個方法:title和subtitle,分別用于顯示注釋的標題和子標題。還有coordinate屬性,返回CLLocationCoordinate2D,表示Annotation的位置
然后,需使用mapView:viewForAnnotation:?方法來返回MKAnnotationView或者MKAnnotationView的子類用來顯示Annotation(注意:這里顯示的不是選中Annotation后的彈出框)?

你可以子類化MKAnnotationView,然后再drawRect:方法里面進行自己的繪制動作(這個方法很蠢)
你完全可以實例化一個MKAnnotationView,然后更改它的image屬性,這樣很簡單。

7、添加移除Annotation
添加一個Annotation
[mapView addAnnotation:annotation];?
添加一個Annotation數組
[mapView addAnnotations:[NSArray arrayWithObjects:annotation1, annotation2, nil]];?
移除一個Annotation
removeAnnotation:?
移除一個Annotation數組
removeAnnotations:?
移除所有Annotation
[mapView removeAnnotations:mapView.annotations];?

8、選中Annotation
一次只能有一個Annotation被選中,選中后會出現CallOut(浮動框)
簡單的CallOut顯示Title和SubTitle,但你也可以自定義一個UIView作為CallOut(與自定義的TableViewCell一樣)

可通過代碼選中Annotation:
selectAnnotation:animated:?
或者取消選擇:
deselectAnnotation:animated:?

9、顯示Annotation
通過mapView:viewForAnnotation:?方法顯示Annotation,每在MapView中加入一個Annotation,就會調用此方法
示例(與tableView:cellForRowAtIndexPath:?很相似)

- (MKAnnotationView *) mapView:(MKMapView *)theMapView?viewForAnnotation:(id <MKAnnotation>) annotation {
static NSString *placemarkIdentifier = @"my annotation identifier";
if ([annotation isKindOfClass:[MyAnnotation class]]) {
?????MKAnnotationView *annotationView = [theMapView?dequeueReusableAnnotationViewWithIdentifier:placemarkIdentifier];
if (annotationView == nil) {
?????????annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation?reuseIdentifier:placemarkIdentifier];
annotationView.image = [UIImage imageNamed:@"blood_orange.png"];
}
else
annotationView.annotation = annotation;
return annotationView;
}
return nil;
}?

10、取得真實地址
示例:
初始化MKReverseGeocoder

MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc]?initWithCoordinate:coordinates];
geocoder.delegate = self;
[geocoder start];?
如果無法處理坐標,則調用reverseGeocoder:didFailWithError:?方法

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder?didFailWithError:(NSError *)error {
NSLog(@"Error resolving coordinates: %@", [error localizedDescription]);
geocoder.delegate = nil;
[geocoder autorelease];
}?
如果成功,則調用reverseGeocoder:didFindPlacemark:?并把信息存儲在MKPlacemark?中
didFindPlacemark:(MKPlacemark *)placemark {
NSString *streetAddress = placemark.thoroughfare;
NSString *city = placemark.locality;
NSString *state = placemark.administrativeArea;
NSString *zip = placemark.postalCode;
// Do something with information
geocoder.delegate = nil;
[geocoder autorelease];
}

轉載于:https://www.cnblogs.com/apem/p/4630080.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Leonbao:MapKit学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲成人经典 | 韩产日产国产欧产 | 变态另类一区 | 国产一区二区三区视频在线播放 | 无码精品国产一区二区三区 | 国产精品久久久久毛片软件 | 中文字幕第一区 | 日中文字幕| 男人桶进美女尿囗 | 国产美女三级无套内谢 | 麻豆高清免费国产一区 | 亚洲婷婷在线视频 | 男人插入女人下面视频 | 欧美性视频网站 | 国产69精品久久久久久久 | 久久精品97 | 亚洲乱码精品久久久久 | 九九九视频在线观看 | 亚洲av中文无码乱人伦在线视色 | 韩国三级在线视频 | 久久国产亚洲精品无码 | 亚洲妇熟xx妇色黄蜜桃 | 糖心logo在线观看 | av一级黄色| 啦啦啦免费高清视频在线观看 | 欧美精品乱人伦久久久久久 | 欧美亚洲一区二区在线观看 | 亚洲午夜精品一区二区三区他趣 | 720url在线观看免费版 | 日韩大片av | 成年视频在线 | 国产日韩欧美激情 | 国产精品久久999 | 亚洲免费在线观看视频 | 日日夜夜添 | 免费看欧美成人a片无码 | 精品麻豆一区二区 | 98自拍视频| 黑人巨茎大战欧美白妇 | 男人午夜免费视频 | 日韩在线观看av | 天天爱天天做天天爽 | 人妖一区二区三区 | 精品一区二区免费看 | 99精品视频在线播放免费 | 久久欧 | 国产精品爱啪在线线免费观看 | 日韩新片王网 | 黑人一级大毛片 | 久久九九久精品国产免费直播 | 69re视频| 人人澡超碰碰 | 99视频在线看 | 成人午夜免费福利 | 国模叶桐尿喷337p人体 | 国产一级一片 | www四虎com| 黄色免费视频观看 | 国产一级二级三级视频 | 和漂亮岳做爰3中文字幕 | 国产91精品ai换脸 | 欧美 日韩 国产 成人 在线 | 亚洲福利视频导航 | 亚洲成人aa | 天堂а√在线中文在线鲁大师 | 国产精品情侣 | 欧美日韩中文国产一区发布 | 国产123| av噜噜噜 | 午夜视频日韩 | 国产在线视频自拍 | 亚洲视频在线观看免费 | 欧美一区 | 五月天丁香久久 | 国产高清视频在线观看 | 国产极品在线观看 | 精品久久久久久无码国产 | 在线一区二区三区 | 蜜桃tv在线观看 | 日韩中文免费 | 日本美女全裸 | 日本作爱视频 | 91人人澡人人爽 | 免费看的黄色录像 | 91美女福利视频 | 午夜一区二区视频 | xxxwww在线观看 | 国产精品久久九九 | 欲色网站 | 国产精品观看 | 国产成人精品在线视频 | 不良视频在线观看 | 天堂欧美城网站网址 | 久久久精品一区二区 | 无码日韩人妻精品久久蜜桃 | 国产欧美在线观看视频 | 久久久久久久色 | 无码免费一区二区三区免费播放 | 亚洲黄色一区二区 |