我不确定这是谷歌地图的新功能,但我认为这个版本的谷歌地图for iOS已经有一个反向地理编码方法......我无法弄清楚如何使用。 In their documentation page,在“相机位置”部分下,它们有一个功能,但它看起来不像SDK附带的功能......或者可能有一些我在这里不明白的东西。有人可以帮忙吗?这是XCode中出现的功能:
- (void)reverseGeocodeCoordinate:(CLLocationCoordinate2D)coordinate
completionHandler:(GMSReverseGeocodeCallback)handler{}
如果我在数组中有坐标,我该如何使用它?如何获取地址和国家/地区以及所有可能的结果?
顺便说一句,这就是他们所拥有的...它是如何比较的:
- (void)mapView:(GMSMapView *)mapView
idleAtCameraPosition:(GMSCameraPosition *)cameraPosition {
id handler = ^(GMSReverseGeocodeResponse *response, NSError *error) {
if (error == nil) {
GMSReverseGeocodeResult *result = response.firstResult;
GMSMarker *marker = [GMSMarker markerWithPosition:cameraPosition.target];
marker.title = result.addressLine1;
marker.snippet = result.addressLine2;
marker.map = mapView;
}
};
[geocoder_ reverseGeocodeCoordinate:cameraPosition.target completionHandler:handler];
}
答案 0 :(得分:2)
您可以尝试此代码
[[GMSGeocoder geocoder]reverseGeocodeCoordinate:CLLocationCoordinate2DMake(latitude, longitude)
completionHandler:^(GMSReverseGeocodeResponse * response, NSError *error){
for(GMSReverseGeocodeResult *result in response.results){
NSLog(@"addressLine1:%@", result.addressLine1);
NSLog(@"addressLine2:%@", result.addressLine2);
}
}];