xcode – 反向地理编码仅以英文返回结果?
发布时间:2020-12-14 19:32:24 所属栏目:百科 来源:网络整理
导读:使用下面的代码,我正在为当前坐标请求反向地理编码. 一切都很好,除了设备设置为与英语不同的语言. 示例:如果设备的语言是意大利语,而我在意大利,则国家的结果是“Italia”而不是“Italy”. 无论设备的语言如何,我如何强制结果只能用英语? CLGeocoder *geoC
使用下面的代码,我正在为当前坐标请求反向地理编码.
一切都很好,除了设备设置为与英语不同的语言. 示例:如果设备的语言是意大利语,而我在意大利,则国家的结果是“Italia”而不是“Italy”. 无论设备的语言如何,我如何强制结果只能用英语? CLGeocoder *geoCoder = [[CLGeocoder alloc] init]; [geoCoder reverseGeocodeLocation:myCurrentLocation completionHandler:^(NSArray *placemarks,NSError *error) { for (CLPlacemark * placemark in placemarks) { [locationController setLastKnownCountry:[placemark country]]; } }]; 谢谢. 解决方法
您必须使用管理每种语言的信息的NSLocale类.然后,对于您的最终翻译,您必须强制使用英语语言环境:
CLGeocoder *geoCoder = [[CLGeocoder alloc] init]; [geoCoder reverseGeocodeLocation:myCurrentLocation completionHandler:^(NSArray *placemarks,NSError *error) { for (CLPlacemark * placemark in placemarks) { //Obtains the country code,that is the same whatever language you are working with (US,ES,IT ...) NSString *countryCode = [placemark ISOcountryCode]; //Obtains a locale identifier. This will handle every language NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]]; //Obtains the country name from the locale BUT IN ENGLISH (you can set it as "en_UK" also) NSString *country = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] displayNameForKey: NSLocaleIdentifier value:identifier]; //Continues your code [locationController setLastKnownCountry:country]; } }]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |