我正在尝试通过reverseGeocodeLocation
获取位置地址,但有时会返回nil地址,如果reverseGeocodeLocation
返回任何特定位置的nil地址,我想要的是附近的地址。
public class func getAddressFrom(location: CLLocation, completion:@escaping ((String?) -> Void)) {
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
if let placemark = placemarks?.first,
let subThoroughfare = placemark.subThoroughfare,
let thoroughfare = placemark.thoroughfare,
let locality = placemark.locality,
let administrativeArea = placemark.administrativeArea {
let address = subThoroughfare + " " + thoroughfare + ", " + locality + " " + administrativeArea
//placemark.addressDictionary
return completion(address)
}
completion(nil)
}
}
答案 0 :(得分:0)
您可能正在达到地理编码器的极限。
摘自docs:
地理编码请求对每个应用都是速率限制的,因此在短时间内提出过多请求可能会导致某些请求失败。超过最大速率时,地理编码器会将带有值网络的错误对象传递给完成处理程序。