我正在使用一个CLGeoCoder
实例通过它的方法来获取一组给定坐标(纬度和经度)的城市和国家reverseGeocodeLocation()
。
该文档指定此数据应位于CLPlacemark
'scountry
和locality
属性中,但结果似乎仅位于addressDictionary
自 iOS 11 以来已弃用的属性内部。
调试实例的图像显示 addressDictionary 存在但既不国家也不地区
因此,这有效,但在以下所有三种用途中显示此警告addressDictionary
:
'addressDictionary' was deprecated in iOS 11.0: Use @properties
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location, preferredLocale: nil) { (placemarksArray, error) in
if let error = error {
print(error)
} else {
if let placemark = placemarksArray?.last {
var city = ""
if let ct = placemark.addressDictionary?["City"] {
city = "\(ct), "
}
var state = ""
if let st = placemark.addressDictionary?["State"] {
state = "\(st), "
}
var country = ""
if let cot = placemark.addressDictionary?["Country"] {
country = "\(cot)"
}
self.cityCountry = "\(city)\(state)\(country)"
}
}
}
我尝试引用属性,但它们只返回 nil 值。
我调用了错误的方法还是这是一个错误?