首页 > 解决方案 > 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

标签: swift

解决方案


有一个变体CLGeocoder.reverseGeocodeLocation()需要一个参数preferredLocale。尝试使用美国英语作为语言环境。那应该这样做。


推荐阅读