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

ios 反地理编码,通过地址获得经纬度

2015-04-09 17:30 666 查看
网上很多都发布了如何使用经纬度来取到具体地名的方法了~这里我就不说了~

由于iphone自带的照片位置信息在地图上显示是有偏移产生的,所以我就找了很多资料想着如何反向的用地址来提取一个正确的经纬度的方法;

以下是核心代码...

NSString *oreillyAddress = @"1005 Gravenstein Highway North, Sebastopol, CA 95472, USA"; //测试使用中文也可以找到经纬度具体的可以多尝试看看~

CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];

[myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *placemarks, NSError *error) {

if ([placemarks count] > 0 && error == nil)

{

NSLog(@"Found %lu placemark(s).", (unsigned long)[placemarks
count]);

CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];

NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);

NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude);

}

else if ([placemarks count] == 0 &&
error == nil)

{

NSLog(@"Found no placemarks.");

}

else if (error != nil)

{

NSLog(@"An error occurred = %@", error);

}

}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐