How to reverse geocode?
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.)
精彩评论