天天看點

反向地理編碼用法

與地圖打交道時,有時需要查找經緯度擷取地理資訊,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);

}

繼續閱讀