iOS强制地理定位以特定语言返回城市名称 [英] iOS Force geolocation to return city name in a specific language

查看:108
本文介绍了iOS强制地理定位以特定语言返回城市名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个相当奇怪的情况:后端开发人员要求我强制执行地理位置返回的城市名称使用特定语言。例如,无论iOS的语言如何,它都会返回哥本哈根而不是哥本哈根。我在网上找不到关于此的任何内容。您的帮助将不胜感激。谢谢

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

推荐答案

不确定这是否是最好和最安全的解决方案,但您可以暂时更改区域设置,同时制作反向地理代码调用并在完成后重置它。

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];
}];

这篇关于iOS强制地理定位以特定语言返回城市名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆