こんにちは、mkreversegeocoder を使用してユーザーの現在の都市を見つけています。動作しますが、別の場所で試してみると、私の国 (トルコ) の自治区/地区の名前が表示されます。たとえば、「イスタンブール」は正しいですが、都市はありません。私の国の「susurluk」のような名前は地区です.都市名ではなく地区を返す理由は何ですか? 必要に応じて、私のコードを投稿します
編集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];
}
}