iOS iOS10适配:地图坐标转中文地址

//联系人:石虎  QQ: 1224614774昵称:嗡嘛呢叭咪哄


之前我们已经知道,在苹果原生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坐标。

下面是处理代码:

[objc] view plain copy
  1. - (void)reverseGeocode:(CLLocationCoordinate2D)coord   
  2. {  
  3.       
  4.     CLLocation *loc;  
  5.       
  6.     CGFloat systemVersion = [[UIDevice currentDevice].systemVersion floatValue];  
  7.     if (systemVersion>=10)  
  8.     {  
  9.         CLLocationCoordinate2D wgs84ToGcj02 = [JZLocationConverter wgs84ToGcj02:coord];  
  10.         loc = [[CLLocation alloc] initWithLatitude:wgs84ToGcj02.latitude longitude:wgs84ToGcj02.longitude];  
  11.     }  
  12.     else  
  13.     {  
  14.         loc = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude];  
  15.     }  
  16.       
  17.     // 反地理编码  
  18.     [self.geocoder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) {  
  19.           
  20.         if (error) {   
  21.   
  22.                 // 有错误  
  23.         }  
  24.         else  
  25.         { // 编码成功  
  26.             // 取出最前面的地址  
  27.             CLPlacemark *pm = [placemarks firstObject];  
  28.             NSLog(@“地名:%@”,pm.name);  
  29.        }  
  30.     }];  
  31.       
  32. }  

谢谢!!!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值