如何在CLLocationManager中强制默认语言为英语?

时间:2016-11-07 16:16:06

标签: ios swift3 cllocationmanager clplacemark

所以,我是swift的新手,我从当前的Lat和Long转换为City名称和Country,它的工作正常:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    if didFindLocation == false
    {
        didFindLocation = true
        locationManager.stopUpdatingLocation()
        userLocation = locations[0]
        long = userLocation.coordinate.longitude;
        lat = userLocation.coordinate.latitude;
        print("\(lat),\(long)")
        converLocationToCity()
    }
}

func converLocationToCity()
{
    let geoCoder = CLGeocoder()
    userLocation = CLLocation(latitude: self.lat, longitude: self.long)
    geoCoder.reverseGeocodeLocation(userLocation, completionHandler:
    {
        (placemarks, error) -> Void in
        var placeMark: CLPlacemark!
        placeMark = placemarks?[0]
        if let city = placeMark.addressDictionary!["State"] as? String
        {
            self.city = city as String
        } else
        {
            self.city = ""
        }
        if let country = placeMark.addressDictionary!["Country"] as? String
        {
            self.country = country as String
        } else
        {
            self.country = ""
        }
        self.currentCity.name = ("\(self.city), \(self.country)" as String)
        print("\(self.currentCity.name)")
        self.fetchWeather.performCurrentWeatherFetch(forSelectedCity: self.currentCity.name)
        DispatchQueue.main.async()
            {
            (self.superview as! UICollectionView).reloadData()
        }
    })
}

但是当设备设置为其他语言时,俄语例如它会返回俄语字符的城市名称和国家/地区,但我需要它只是英语,请任何人提出一些想法或建议吗?谢谢!

1 个答案:

答案 0 :(得分:0)

这是我的解决方案 在获取位置数据时,我更改了“UserDefaults.standard.set([”base“],forKey:”AppleLanguages“)'

一旦我收到英文字典,我就删除了对象

<button (click)="goBack(stepper)" type="button" [disabled]="stepper.selectedIndex === 0">Back</button> <button (click)="goForward(stepper)" type="button" [disabled]="stepper.selectedIndex === stepper._steps.length-1">Next</button>

然后将applelanguage设置为默认值

UserDefaults.standard.removeObject(forKey: "AppleLanguages")