When using my app in a foreign country, the google GMSGeocoder
is returning the response in local language automatically. how can I set it to always return the the response in English?
Im using GMS SDK 1.7 and my code is something like this:
GMSGeocoder *geoCoder = [[GMSGeocoder alloc] init];
[geoCoder reverseGeocodeCoordinate:self.cellLocation.coordinate completionHandler:^(GMSReverseGeocodeResponse *respones, NSError *err) {
if([respones firstResult]) {
GMSAddress* address = [respones firstResult];
NSString* fullAddress = [NSString stringWithFormat:@"%@, %@",address.thoroughfare, address.locality];
self.theTextField.text = fullAddress;
} else {
self.theTextField.text = @"";
}
}];
Using a GMSGeocoder category can solve this issue, inspired by @DaNLtR After that , It can set geocoder result as English .
@implementation GMSGeocoder (Load)
+(void)load {
[[self class] setUserLanguage:@"en-CN"];// set your wanted language.
NSLog(@"GMSGeocoder + load!");
}
- (void)dealloc {
[[self class] resetSystemLanguage];
NSLog(@"GMSGeocoder + dealloc!");
}
+ (void)setUserLanguage:(NSString *)userLanguage
{
if (!userLanguage.length) {
[[self class] resetSystemLanguage];
return;
}
[[NSUserDefaults standardUserDefaults] setValue:userLanguage forKey:@"UserLanguage"];
[[NSUserDefaults standardUserDefaults] setValue:@[userLanguage] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
+ (void)resetSystemLanguage
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"UserLanguage"];
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
@end
Why should in category?
A:I tested setLanguage: before GMSGeocoder reverseGeocodeCoordinate method, it can't affect geocoder result. After I saw DaNLtR's answer , I think we can setLanguge in load method.
Why should reset language?
A:Avoide affect other module or framework .
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