首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CLGeocoder误差GEOErrorDomain码=-3

CLGeocoder误差GEOErrorDomain码=-3
EN

Stack Overflow用户
提问于 2016-11-22 06:36:46
回答 1查看 4.3K关注 0票数 6

当我尝试使用反向地理编码时,出现了这个错误消息。

地理代码错误:错误Domain=GEOErrorDomain代码=-3“(空)”

我的代码如下:

代码语言:javascript
复制
import CoreLocation
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
    if let placemarks = placemarks {
        reverseGeocodeLocations[hash] = placemarks
    }
    callback(placemarks, error)
}

这只是一次又一次的工作,我每秒钟请求几次reverseGeocode。所以我想这个错误信息是与请求的限制有关还是什么的?有关于苹果公司的地理代码请求的文档吗?谢谢你提前。

已更新

这是我请求的全部代码

代码语言:javascript
复制
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")
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-03 14:10:37

在到处搜索答案之后,它是在Apples!:/

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

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

在检查完成处理程序中的错误代码时,确实是网络错误:2

希望这能帮到别人!

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40735302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档