如何以阿拉伯语言获取位置详细信息 我尝试了这段代码,但我总是用英语。
func fetchCountryAndCity(location: CLLocation, completion: @escaping (String, String, String) -> ())
{
//let gg : GMSGeocoder = GMSGeocoder()
let geo : CLGeocoder = CLGeocoder()
geo.accessibilityLanguage = "ar"
geo.reverseGeocodeLocation(location) { placemarks, error in
if let error = error {
print(error)
} else if let country = placemarks?.first?.country,
let city = placemarks?.first?.locality , let SubAdminArea = placemarks?.first?.subLocality {
completion(country, city , SubAdminArea)
}
}
}
答案 0 :(得分:0)
从iOS 11开始,您可以将区域设置传递给reverseGeocodeLocation
请求。这将返回沙特阿拉伯阿拉伯语的所有结果:
let locale = Locale(identifier: "ar_sa")
CLGeocoder().reverseGeocodeLocation(location, preferredLocale: locale) { placemarks, error in
// ...
}
适用于iOS< 11 ,您必须暂时将应用的首选语言更改为阿拉伯语:
// Switch your app's preferred language to Arabic
UserDefaults.standard.set(["ar"], forKey: "AppleLanguages")
CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
// Remove the language override
UserDefaults.standard.removeObject(forKey: "AppleLanguages")
// ...
}
(原谅我的无知,因为我不知道如何阅读阿拉伯语所以我不知道结果是否正确)