gpt4 book ai didi

ios - CLGeocoder 错误。 GEOErrorDomain 代码=-3

转载 作者:可可西里 更新时间:2023-11-01 03:48:41 26 4
gpt4 key购买 nike

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

Geocode error: Error Domain=GEOErrorDomain Code=-3 "(null)"

我的代码如下:

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

这只是偶尔有效,我每秒请求 reverseGeocode 几次。所以我猜这个错误消息与请求限制有关?有没有关于苹果地理编码请求的文档?感谢您的提前。


已更新

这是我请求的全部代码

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")
}
}
}
}

最佳答案

在到处寻找答案后,它在 Apples 文档中! :/

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.

在完成处理程序中检查错误代码时确实是 Network Error:2

希望这对某人有帮助!

关于ios - CLGeocoder 错误。 GEOErrorDomain 代码=-3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40735302/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com