开发者

How to reverse geocode?

开发者 https://www.devze.com 2023-02-04 04:39 出处:网络
I my iPhone application I have to find the city and country name of current location. How it开发者_开发技巧 can be done?

I my iPhone application I have to find the city and country name of current location. How it开发者_开发技巧 can be done?

Thanks


MKReverseGeocoder: http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html

MKReverseGeocoderDelegate: http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoderDelegate_Protocol/Reference/Reference.html

You need MapKit for this.

Example (given myCoor)

- (void)awakeFromNib {
  MKReverseGeocoder *rg = [[MKReverseGeocoder alloc] initWithCoordinate:myCoor];
  rg.delegate = self;
  [rg start];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
  NSLog(@"%@, %@", placemark.locality, placemark.country);
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
  NSLog(@"%@", error);
}

(In example I didn't care about memleaks but as I see from your profile you're a Java developer (where memory management is no problem), I recommend you do.)

0

精彩评论

暂无评论...
验证码 换一张
取 消