简体   繁体   English

使用CLGeocoder转发地理编码示例

[英]Forward Geocode Example using CLGeocoder

A directions to a working example or some guidance on how to use the forward geocoding beside the Apple Documentation. 有关如何在Apple文档旁边使用正向地理编码的工作示例或指导的说明。 Thats pretty generic (i cant understand) 多数民众赞成在一般(我不明白)

Please this would be great! 请这太好了! Also does anyone know if they are using Google API to achieve the same or their own? 也有人知道他们是否使用Google API实现相同或自己的?

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];
    }];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM