设为首页 加入收藏

TOP

地图篇-03.展示地图(四)
2017-10-13 10:28:36 】 浏览:9097
Tags:地图 -03. 展示
e recreated.
60 } 61 /** 62 * 当用户位置更新的时候调用 63 * 64 * @param mapView 当前地图 65 * @param userLocation 用户位置 66 */ 67 -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { 68 //反地理编码 69 CLGeocoder *reverseGeo = [[CLGeocoder alloc] init]; 70 //MKUserLocation-userLocation的属性 71 /* 72 // 如果用户的位置正在更新,返回YES. 73 @property (readonly, nonatomic, getter=isUpdating) BOOL updating; 74 75 // 如果MKMapView.showsUserLocation=NO或者用户的位置尚未确定,返回nil. 76 @property (readonly, nonatomic, nullable) CLLocation *location; 77 78 // 如果不适用MKUserTrackingModeFollowWithHeading返回nil; 79 @property (readonly, nonatomic, nullable) CLHeading *heading NS_AVAILABLE(10_9, 5_0); 80 81 // 描述用户当前位置的文本. 82 @property (nonatomic, copy, nullable) NSString *title; 83 84 // 描述用户当前位置的详细信息. 85 @property (nonatomic, copy, nullable) NSString *subtitle; 86 */ 87 [reverseGeo reverseGeocodeLocation:userLocation.location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) { 88 //判断,如果返回的地标为空,或者error存在的时候 89 if (placemarks.count == 0 || error) { 90 NSLog(@"地理编码失败"); 91 return; 92 } 93 94 95 96 //根据userLocation.location进行反地理编码获得的地址只有一个(地理编码小节中有讲) 97 CLPlacemark *clp = [placemarks firstObject]; 98 //设置用户当前位置的地址 99 userLocation.title = clp.name; 100 //设置用户当前位置的详细信息 101 userLocation.subtitle = @"那小子真帅...";//这里可以打印街道,门牌号等等,这里举例. 102 103 104 }]; 105 106 } 107 108 /** 109 * 地图的范围已经改变的时候调用 110 */ 111 -(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { 112 //纬度的跨度 113 CLLocationDegrees latitudeDelta = mapView.region.span.latitudeDelta; 114 //经度的跨度 115 CLLocationDegrees longitudeDelta = mapView.region.span.longitudeDelta; 116 117 NSLog(@"纬度的跨度:%f,经度的跨度:%f",latitudeDelta,longitudeDelta); 118 } 119 /** 120 * 地图的范围将要改变的时候调用 121 */ 122 -(void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { 123 124 } 125 @end

运行效果图:

使用这个属性,系统会自动给你选择一个合适的范围.

 

好了,展示地图小节就到此为止了,大家如果觉得有什么问题或者哪里不足都可以告诉我.谢谢

 

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Xcode4快速Doxygen文档注释 — 简.. 下一篇Android与Swift iOS开发:语言与..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目