MKReverseGeocoder返回不是城市的城市?

时间:2011-09-05 08:52:41

标签: iphone objective-c gps cllocationmanager mkreversegeocoder

您好我正在使用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];

  }

}

1 个答案:

答案 0 :(得分:1)

您可以使用google地图api获取正确答案,您必须在该地图api中发送该地点的纬度/经度,您将以json / xml的形式获得答案。请查看此问题

Reverse Geocoding With Google Map API And PHP To Get Nearest Location Using Lat,Long coordinates