swift - Swift Reverse Geocoding get name of state always in same language
问题描述
i need to get the name of the state where the user is. To do so i created the following method:
func getState(){
if location != nil{
CLGeocoder().reverseGeocodeLocation(location)
{ (placemarks, error) -> Void in
if error != nil {}
else
{
let pm = CLPlacemark(placemark: placemarks![0] as CLPlacemark)
var subThoroughtare:String = ""
var thoroughfare:String = ""
var subLocality:String = ""
var subAdministrativeArea:String = ""
var postalCode:String = ""
var country:String = ""
if pm.subThoroughfare != nil {subThoroughtare = pm.subThoroughfare!}
if pm.thoroughfare != nil {thoroughfare = pm.thoroughfare!}
if pm.subLocality != nil {subLocality = pm.subLocality!}
if pm.subAdministrativeArea != nil {subAdministrativeArea = pm.subAdministrativeArea!}
if pm.postalCode != nil {postalCode = pm.postalCode!}
if pm.country != nil {country = pm.country!}
let state = pm.administrativeArea;
self.filterDataSet(state: state!)
}
}
}
}
The problem is that the name of the state is always in the phones language, but i need it in english. How can i set it to english as default
解决方案
有一个变体CLGeocoder.reverseGeocodeLocation()
需要一个参数preferredLocale
。尝试使用美国英语作为语言环境。那应该这样做。
推荐阅读
- json - 如何在 Scala 中将 Scala 文档转换为 JSON
- lua - 如何从 Lua 中的字符串中删除某些特殊字符?
- wordpress - Redirect question mark URL to the original URL
- c# - 有关如何在 .NET 5.0 Worker 服务中使用 DI 最好地注册 EventGridClient 的指南
- arrays - 在 C 中创建一个函数以返回 int 数组的长度
- c++ - SymFromAddr 结果在 Release 环境中为 false
- google-data-studio - 如何在 Google Data Studio 中聚合 2 个维度?
- excel - 从 MySQL PHP 报告的 excel 导出中的 & 符号问题
- arrays - 如何检测何时到达反应功能组件中的数组末尾?
- ios - 有没有办法用新值重新填充数组,而不使用 for 循环?