0

我想从 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

4

1 回答 1

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);
}
于 2013-05-21T12:34:41.117 回答