xcode 使用 CLGeocoder 的正向地理编码示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9771221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Forward Geocode Example using CLGeocoder
提问by carbonr
A directions to a working example or some guidance on how to use the forward geocoding beside the Apple Documentation. Thats pretty generic (i cant understand)
工作示例的说明或有关如何使用 Apple 文档旁边的正向地理编码的一些指导。那太笼统了(我看不懂)
Please this would be great! Also does anyone know if they are using Google API to achieve the same or their own?
请这会很棒!还有谁知道他们是使用 Google API 来实现相同的还是他们自己的?
回答by carbonr
Found this to work, though i will post it here if someone else finds it useful.
发现它可以工作,但如果其他人觉得它有用,我会在这里发布。
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:PlaceName.text completionHandler:^(NSArray *placemarks, NSError *error) {
//Error checking
CLPlacemark *placemark = [placemarks objectAtIndex:0];
MKCoordinateRegion region;
region.center.latitude = placemark.region.center.latitude;
region.center.longitude = placemark.region.center.longitude;
MKCoordinateSpan span;
double radius = placemark.region.radius / 1000; // convert to km
NSLog(@"Radius is %f", radius);
span.latitudeDelta = radius / 112.0;
region.span = span;
[mapView setRegion:region animated:YES];
}];