我正在尝试通过 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)
}
}
最佳答案
您可能达到了地理编码器的极限。
摘自 docs :
Geocoding requests are rate-limited for each app, so making too many requests in a short period of time may cause some of the requests to fail. When the maximum rate is exceeded, the geocoder passes an error object with the value network to your completion handler.
关于ios - 如果位置地址为零,如何通过reverseGeocodeLocation获取附近的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43318066/