iOS10适配:地图坐标转中文地址
2016-09-22 11:14
477 查看
之前我们已经知道,在苹果原生SDK中,CoreLocation使用的都是地理坐标系WGS1984标准,在iOS10之前一直是这样的;
但是升级到iOS10以后,我们发现使用CLGeocoder类中的实例方法- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler将经纬度转中文地址的结果跟iOS9.3中不一致;
经过多次调试,得出结论是:在iOS10系统版本中用CLGeocoder类中的实例方法- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler传入CoreLocation框架获取的经纬度转中文地名的时候,必需先将获取的WGS1984经纬度转换成GCJ-02坐标。
下面是处理代码:
各个坐标系的相互转换请跳转到我的另一篇文章:国内涉及到的地图坐标系的转换 http://blog.csdn.net/jijiji000111/article/details/52468042
但是升级到iOS10以后,我们发现使用CLGeocoder类中的实例方法- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler将经纬度转中文地址的结果跟iOS9.3中不一致;
经过多次调试,得出结论是:在iOS10系统版本中用CLGeocoder类中的实例方法- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler传入CoreLocation框架获取的经纬度转中文地名的时候,必需先将获取的WGS1984经纬度转换成GCJ-02坐标。
下面是处理代码:
- (void)reverseGeocode:(CLLocationCoordinate2D)coord { CLLocation *loc; CGFloat systemVersion = [[UIDevice currentDevice].systemVersion floatValue]; if (systemVersion>=10) { CLLocationCoordinate2D wgs84ToGcj02 = [JZLocationConverter wgs84ToGcj02:coord]; loc = [[CLLocation alloc] initWithLatitude:wgs84ToGcj02.latitude longitude:wgs84ToGcj02.longitude]; } else { loc = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude]; } // 反地理编码 [self.geocoder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) { if (error) { // 有错误 } else { // 编码成功 // 取出最前面的地址 CLPlacemark *pm = [placemarks firstObject]; NSLog(@“地名:%@”,pm.name); } }]; }
各个坐标系的相互转换请跳转到我的另一篇文章:国内涉及到的地图坐标系的转换 http://blog.csdn.net/jijiji000111/article/details/52468042
相关文章推荐
- iOS如何保持程序在后台长时间运行
- iOS10.0 跳转后标题按钮都没了,点击事件也没有
- iOS10 推送证书问题
- iOS开发之导航栏titleView不居中的问题
- DELL 755重置BIOS设置教程
- iOS如何获取iOS应用中所有图片资源
- iOS实时卡顿监控
- Xcode8以及iOS10问题总结!
- iOS调试
- iOS高效调试
- NSURLSESSION学习笔记(一)简介
- iOS 10 适配
- 关于iframe页面嵌入后在ios设备上position=fixed属性失效的解决办法
- 关于Xcode报错, 但编译,运行正常情况
- 在工程中加入第三方库
- iOS10 推送最新配置
- iOS 音频拼接
- [iOS Xcode8兼容] Xcode8下运行iOS7 (Could not locate device support files.)
- iOS AFNetWorking文件断点下载
- Xcode8.0、iOS10.0关于推送的问题