简体   繁体   English

CLGeocoder错误。 GEOErrorDomain代码= -3

[英]CLGeocoder error. GEOErrorDomain Code=-3

When I tried to use reverse geocoding,this error message showed up. 当我尝试使用反向地理编码时,出现此错误消息。

Geocode error: Error Domain=GEOErrorDomain Code=-3 "(null)" 地理编码错误:错误域= GEOErrorDomain代码= -3“(null)”

My code is below: 我的代码如下:

import CoreLocation
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
    if let placemarks = placemarks {
        reverseGeocodeLocations[hash] = placemarks
    }
    callback(placemarks, error)
}

This works only time to time, and I request reverseGeocode several times per seconds. 这只是不时工作,我每秒多次请求reverseGeocode。 So I guess this error message is related to the limit of request or something? 所以我猜这个错误信息与请求的限制有什么关系? Is there any documentation about apple's geocode request? 有没有关于apple的地理编码请求的文档? Thanks for advance. 谢谢你提前。


Updated 更新

here is my entire code for requesting 这是我的整个代码请求

import CoreLocation

fileprivate struct ReverseGeocodeRequest {

    private static let geocoder = CLGeocoder()
    private static var reverseGeocodeLocations = [Int: [CLPlacemark]]()
    private static let reverseGeocodeQueue = DispatchQueue(label: "ReverseGeocodeRequest.reverseGeocodeQueue")

    private static var nextPriority: UInt = 0

    fileprivate static func request(location: CLLocation, callback: @escaping ([CLPlacemark]?, Error?)->Void) {
        let hash = location.hash
        if let value = reverseGeocodeLocations[hash] {
            callback(value, nil)
        } else {
            reverseGeocodeQueue.async {
                guard let value = reverseGeocodeLocations[hash] else {
                    geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
                        if let placemarks = placemarks {
                            reverseGeocodeLocations[hash] = placemarks
                        }
                        callback(placemarks, error)
                    }
                    return
                }
                callback(value, nil)
            }
        }
    }



    let priority: UInt
    let location: CLLocation
    let handler : ([CLPlacemark]?, Error?)->Void

    private init (location: CLLocation, handler: @escaping ([CLPlacemark]?, Error?)->Void) {
        ReverseGeocodeRequest.nextPriority += 1
        self.priority = ReverseGeocodeRequest.nextPriority
        self.location = location
        self.handler  = handler
    }

}

extension ReverseGeocodeRequest: Comparable {
    static fileprivate func < (lhs: ReverseGeocodeRequest, rhs: ReverseGeocodeRequest) -> Bool {
        return lhs.priority < rhs.priority
    }
    static fileprivate func == (lhs: ReverseGeocodeRequest, rhs: ReverseGeocodeRequest) -> Bool {
        return lhs.priority == rhs.priority
    }

}


extension CLLocation {

    func reverseGeocodeLocation(callback: @escaping ([CLPlacemark]?, Error?)->Void) {
        ReverseGeocodeRequest.request(location: self, callback: callback)
    }

    func getPlaceName(callback: @escaping (Error?, String?)->Void) {
        self.reverseGeocodeLocation { (placemarks, error) in
            guard let placemarks = placemarks, error == nil else {
                callback(error, nil)
                return
            }
            guard let placemark = placemarks.first else {
                callback(nil, "Mysterious place")
                return
            }

            if let areaOfInterest = placemark.areasOfInterest?.first {
                callback(nil, areaOfInterest)
            } else if let locality = placemark.locality {
                callback(nil, locality)
            } else {
                callback(nil, "On the Earth")
            }
        }
    }
}

After searching everywhere for the answer it was in Apples docs! 在搜索到答案后,它在Apples文档中! :/ :/

https://developer.apple.com/reference/corelocation/clgeocoder/1423621-reversegeocodelocation https://developer.apple.com/reference/corelocation/clgeocoder/1423621-reversegeocodelocation

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. 超过最大速率时,地理编码器会将带有值网络的错误对象传递给完成处理程序。

When checking the error code in the completion handler it is indeed Network Error:2 在完成处理程序中检查错误代码时,确实是网络错误:2

Hope this helps someone! 希望这有助于某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法确定当前的国家/地区代码:Error Domain = GEOErrorDomain Code = -2“操作无法完成。 (GEOErrorDomain错误-2。)” - Could not determine current country code: Error Domain=GEOErrorDomain Code=-2 “The operation couldn’t be completed. (GEOErrorDomain error -2.)” IOS 9问题:CLGeocoder网络错误代码2 - IOS 9 issue : CLGeocoder Network error code 2 CLGeocoder reverseGeocodeLocation“kCLErrorDomain error 2” - CLGeocoder reverseGeocodeLocation “kCLErrorDomain error 2” CLGeocoder reverseGeocodeLocation错误-8 - CLGeocoder reverseGeocodeLocation error -8 NEHotspotConfigurationErrorDomain Code=8“内部错误。” - NEHotspotConfigurationErrorDomain Code=8 "internal error." 使用CLGeocoder获取邮政编码 - Getting Postal Code using CLGeocoder 无法在iOS中获取位置(GEOErrorDomain代码= -204) - Can't get Location in iOS (GEOErrorDomain Code=-204) CLGeocoder速率限制错误-替代品? - CLGeocoder rate limited error - alternatives? CLGeocoder reverseGeocodeLocation返回&#39;kCLErrorDomain错误9&#39; - CLGeocoder reverseGeocodeLocation returns 'kCLErrorDomain error 9' iOS didFailToConnectPeripheral:错误代码= 0“未知错误”。 - iOS didFailToConnectPeripheral: with error Code=0 “Unknown error.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM