您的位置:首页 > 移动开发 > IOS开发

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坐标。

下面是处理代码:

- (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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: