`

反向地理编码用法

阅读更多
与地图打交道时,有时需要查找经纬度获取地理信息,MapKit提供了一种工具--反向地理编码 MKReverseGeocoder

MKReverseGeocoder *reverseGeocoder =[[[MKReverseGeocoder alloc] initWithCoordinate:self.mapView.userLocation.location.coordinate] autorelease];
    NSLog(@"%g",self.mapView.userLocation.location.coordinate.latitude);
    NSLog(@"%g",self.mapView.userLocation.location.coordinate.longitude);
   reverseGeocoder.delegate = self;
    [reverseGeocoder start];

然后实现下面两个代理方法即可获得你想要的地理信息
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
    NSLog(@"MKReverseGeocoder has failed.");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
    NSLog(@"当前地理信息为:%@",placemark.locality);
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics