Swift 5 reverseGeocodeLocation() 导致不推荐使用 addressDictionary
Swift 5 reverseGeocodeLocation() result in deprecated addressDictionary
我正在使用 CLGeoCoder
实例通过其方法 reverseGeocodeLocation()
.
获取给定坐标集(纬度和经度)的城市和国家/地区
文档指定此数据应在 CLPlacemark
的 country
和 locality
属性中,但结果似乎只在 addressDictionary
[=35= 中] 自 iOS 11.
以来已弃用
Image of debugging instance showing addressDictionary present but neither country nor locality
这因此有效,但在 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)"
}
}
}
我尝试引用这些属性,但它们只是 return 零值。
我调用了错误的方法还是这是一个错误?
突然对 country
、locality
和 subAdministrativeArea
的引用开始起作用了!无法弄清楚是什么原因导致他们不早点工作。
我正在使用 CLGeoCoder
实例通过其方法 reverseGeocodeLocation()
.
文档指定此数据应在 CLPlacemark
的 country
和 locality
属性中,但结果似乎只在 addressDictionary
[=35= 中] 自 iOS 11.
Image of debugging instance showing addressDictionary present but neither country nor locality
这因此有效,但在 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)"
}
}
}
我尝试引用这些属性,但它们只是 return 零值。
我调用了错误的方法还是这是一个错误?
突然对 country
、locality
和 subAdministrativeArea
的引用开始起作用了!无法弄清楚是什么原因导致他们不早点工作。