MKReverseGeocoder returns cities that are not a city?
Hi i am using mkreversegeocoder to find the users current city.It works but when i try it in another location it gives the names of borough/district in my country (Turkey).For example it gives "istanbul" correct but there is no city name like "susurluk" in my country it is a district.Any idea why it returns me districts instead of city name? if you want i would post my code's
edit 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] initWithC开发者_如何学JAVAoordinate: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];
}
}
You can get the correct answer by using the google map api in which you have to send the lat/long of the place and you will get answer in the form of json/xml. Please check out this question
Reverse Geocoding With Google Map API And PHP To Get Nearest Location Using Lat,Long coordinates
精彩评论