5

I'm using CLLocationManager on iPhone to get the current user location, then I use reverseGeocodeLocation to convert the location to an address.

This works fine but the results are returned in the device language and I need them to always be in english.

Is there a way to get the Address string in a desired language or convert it ?

    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
        if (error == nil && [placemarks count] > 0) {
            placemark = [placemarks lastObject];
    }

2 Answers 2

7

I managed to figure it out eventually so this is for those who might need it as well.

  1. Get the "AppleLanguages" key from SUserDefaults standardUserDefaults and save it for later.
  2. Set the "AppleLanguages key to only "en"
  3. Grab the location (Now it's only in english)
  4. Restore the "AppleLanguages" key from before.

//1+2

NSArray *currentLanguageArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
         //get the location

//4

[[NSUserDefaults standardUserDefaults] setObject:currentLanguageArray forKey:@"AppleLanguages"];

Hope that helps

2

CLGeocoder provides a handy method for this exact case:

- (void)reverseGeocodeLocation:(CLLocation *)location 
               preferredLocale:(NSLocale *)locale 
             completionHandler:(CLGeocodeCompletionHandler)completionHandler;

Available in iOS 11 and above.

1
  • Swift: func reverseGeocodeLocation(_ location: CLLocation, preferredLocale locale: Locale?, completionHandler: @escaping CLGeocodeCompletionHandler)
    – Rool Paap
    Commented Oct 11, 2019 at 12:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.