ios - 如果位置地址为零,如何通过reverseGeocodeLocation获取附近的地址?

标签 ios iphone swift reversegeocodelocation

我正在尝试通过 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/

相关文章:

ios - 使用 Cocoapods 的 Google Analytics 3.17 for iOS 现在支持 Bitcode 吗?

ios - Storyboard中的自定义segue

ios - 如何根据swift 3中静态表格 View 中的文本增加textview大小

iphone - 使用 iPhone MapKit 自定义 map

php - Swift - JSON 响应以\u201c 开头并以\u201d 结尾

ios - 黑色主题的应用程序会因为 iPhone X 缺口而在 App Store 上被拒绝吗?

iphone - Xcode目标架构

iphone - 如何在 iPhone 中将标签拖放到 UIToolbarItem 上

iphone - 如何将 iPhone 应用程序中的标签文本分享到 Facebook?

ios - 如何在 SwiftUI 中向下翻页矩形?