I've encountered a rather strange situation where the backend developer asked me to force the city name that is returned from performing a geolocation to be in a specific language? For instance have it return København instead of Copenhagen no matter what language the iOS is to. I couldn't find anything on the web regarding this. Your help will be much appreciated. Thanks
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Not sure if this is the best and safest solution but you could temporarily change the locale while you make the reverse geo code call and then reset it when you are done.
NSArray *defaultLanguages = [[NSUserDefaults standardUserDefaults] valueForKey:@"AppleLanguages"];
NSArray *languages = [NSArray arrayWithObject:@"da"];
[[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
CLLocation *location = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = placemarks[0];
NSString *danish = placemark.country;
[[NSUserDefaults standardUserDefaults] setObject:defaultLanguages forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
}];