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];
}
I managed to figure it out eventually so this is for those who might need it as well.
//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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With