从Google地方搜索中查找地名

时间:2013-05-21 12:21:22

标签: objective-c google-maps google-places-api

我想从lat和long找到地名。我正在使用google place api。 我怎样才能实现这个目标

现在我可以使用此

在该纬度附近搜索

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

1 个答案:

答案 0 :(得分:1)

您可以使用MKReverseGeoCoder获取给定纬度和经度的名称,区域,信息等。但是,请注意它已被弃用。

ViewController应该是MKReverseGeocoderDelegate的委托。 MKReverseGeoCoder的示例用法是;

- (void)viewDidLoad {
    CLLocationCoordinate2D coordinates;

    coordinates.latitude = 33.8670522;
    coordinates.longitude = 151.1957362;

    CLLocation *location = [[CLLocation alloc] initWithLatitude:coordinates.latitude longitude:coordinates.longitude];

    MKReverseGeocoder* rev = [[MKReverseGeocoder alloc] initWithCoordinate:location.coordinate];
    rev.delegate = self;
    [rev start];
    [super viewDidLoad];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
    NSLog(@"Error with reverse geo coder.");
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {

    NSLog(@"Geo coder finished successfully");

    NSString *administrativeArea = placemark.administrativeArea;
    NSString *thoroughfare = placemark.thoroughfare;

    NSLog(@"%@ %@", administrativeArea, thoroughfare);
}