我的iPhone应用程序我必须找到当前位置的城市和国家/地区名称。怎么做?
由于
答案 0 :(得分:2)
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
你需要MapKit。
- (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);
}
(例如我并不关心memleaks,但正如我从你的个人资料中看到你是一个Java开发人员(内存管理没有问题),我建议你这样做。)