Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to localize address result from reverseGeocodeLocation?

Tags:

My iphone app supposed to resolve address based on latitude and longitude of the user. reverseGeocodeLocation works fine, but results are in english.

Is there a way to localize the results to other languages?

couldnt find any information about it at apple or anywhere else.

The code I use is:

CLGeocoder *geocoder = [[[CLGeocoder alloc] init] autorelease]; CLLocation *location = [[[CLLocation alloc]         initWithLatitude:coord.latitude longitude:coord.longitude] autorelease];  [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {     NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");      if (error){         NSLog(@"Geocode failed with error: %@", error);         [self displayError:error];         return;     }     if(placemarks && placemarks.count > 0)     {       //do something         CLPlacemark *topResult = [placemarks objectAtIndex:0];          NSString *addressTxt = [NSString stringWithFormat:@"%@ %@,%@ %@",             [topResult subThoroughfare],[topResult thoroughfare],            [topResult locality], [topResult administrativeArea]];     } } 
like image 294
user513790 Avatar asked Jan 10 '12 19:01

user513790


2 Answers

i found how to localize country name, maybe it'll help:

CLPlacemark *placemark;  NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: placemark.ISOcountryCode forKey: NSLocaleCountryCode]]; NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; NSString *country = [usLocale displayNameForKey: NSLocaleIdentifier value: identifier]; 

insert any country id instead @"en_US"

like image 97
rozochkin Avatar answered Sep 19 '22 11:09

rozochkin


Solution for Swift 4, iOS 11

You can force to get geocoding results in chosen locale language by setting argument: preferredLocale: Locale.init(identifier: "en_US").

CLGeocoder().reverseGeocodeLocation(location, preferredLocale: Locale.init(identifier: "en_US"), completionHandler: {(placemarks, error) -> Void in     print(location)      if error != nil {         print("Reverse geocoder failed with error" + error!.localizedDescription)         return     }      if placemarks!.count > 0 {         let pm = placemarks![0]         print(pm.administrativeArea!, pm.locality!)     }     else {         print("Problem with the data received from geocoder")     } }) 
like image 26
deevee Avatar answered Sep 20 '22 11:09

deevee