嗨,我正在使用me地理编码器来查找用户当前的city.It工程,但当我在另一个位置尝试它时,它给出了我的国家(土耳其)的自治市/地区的名称,例如,它给出了“伊斯坦布尔”的正确名称,但在我的国家没有像“苏苏鲁克”这样的城市名称这是一个district.Any的想法,为什么它返回我的地区,而不是城市名称?如果你愿意,我会把我的代码贴出来
编辑1:
-(void)viewDidLoad {
[super viewDidLoad];
manager=[[CLLocationManager alloc]init];
manager.delegate=self;
manager.desiredAccuracy=kCLLocationAccuracyBest;
[manager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)aManager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
geocoder.delegate=self;
[geocoder start];
[manager startUpdatingLocation];
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
NSDictionary * addressDict= [placemark addressDictionary];
//NSString *country = [addressDict objectForKey:@"Country"];
NSString *city = [addressDict objectForKey:@"City"];
//change the country name into en_US
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
NSString *country1 = [usLocale displayNameForKey: NSLocaleCountryCode value: countryCode];
[[NSUserDefaults standardUserDefaults] setObject:country1 forKey:@"country"];
[[NSUserDefaults standardUserDefaults] setObject:city forKey:@"city"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
if (error.code == kCLErrorHeadingFailure) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Problem"
message:@"Can't find the location!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertView show];
[alertView release];
[manager stopUpdatingLocation];
}
}
-(void)locationManager:(CLLocationManager *)manager1 didFailWithError:(NSError *)error {
if (error.code != kCLErrorDenied) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Problem"
message:@"Can't find the location!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertView show];
[alertView release];
[manager stopUpdatingLocation];
}
}发布于 2011-09-05 17:38:37
您可以通过使用google map api获得正确的答案,在该api中,您必须发送地点的经度/纬度,您将获得json/xml格式的答案。请查看此问题
Reverse Geocoding With Google Map API And PHP To Get Nearest Location Using Lat,Long coordinates
https://stackoverflow.com/questions/7305779
复制相似问题