用地址来提取一个正确的经纬度的方法;
以下是核心代码...
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);
}
}];
原文地址:http://blog.sina.com.cn/s/blog_63b4ee0d0101ghh6.html