【问题标题】:How to get nearby address through reverseGeocodeLocation if location address is nil?如果位置地址为零,如何通过 reverseGeocodeLocation 获取附近地址?
【发布时间】:2017-04-10 08:20:04
【问题描述】:

我试图通过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)
        }
    }

【问题讨论】:

    标签: ios iphone swift reversegeocodelocation


    【解决方案1】:

    您可能正在达到地理编码器的极限。

    摘自docs

    每个应用的地理编码请求都有速率限制,因此在短时间内发出过多请求可能会导致某些请求失败。当超过最大速率时,地理编码器将带有值网络的错误对象传递给您的完成处理程序。

    【讨论】:

    • 我没有收到错误,只是位置没有地址,我只是在位置发生变化时请求reverseGeocodeLocation
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 2018-06-22
    相关资源
    最近更新 更多