MKReverseGeocoder возвращает города, которые не являются городом? - PullRequest
1 голос
/ 05 сентября 2011

Привет, я использую mkreversegeocoder, чтобы найти текущий город пользователей. Это работает, но когда я пробую его в другом месте, он дает названия районов / районов в моей стране (Турция). Например, он дает правильный «Стамбул», но тамв моей стране нет такого названия города, как "сусурлук", это район. Любая идея, почему он возвращает мне районы вместо названия города?если вы хотите, я бы опубликовал мой код

изменить 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 Ответ

1 голос
/ 05 сентября 2011

Вы можете получить правильный ответ, используя API-интерфейс карты Google, в котором вам нужно отправить широту / длину места, и вы получите ответ в виде json / xml. Пожалуйста, проверьте этот вопрос

Обратное геокодирование с помощью Google Map API и PHP для получения ближайшего местоположения с использованием широты, длинных координат

...