CLGeocoder error. Code GEOErrorDomain = -3

When I tried to use reverse geocoding, this error message appeared.

Geocoding Error: Error Domain = GEOErrorDomain Code = -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 only works from time to time, and I request reverseGeocode several times per second. So, I think this error message is related to the request limit or something else? Is there any documentation about the geocoding request for apples? Thanks for the promotion.


Update

here is my whole code for the request

 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") } } } } 
+6
source share
2 answers

After searching everywhere for an answer, he was in the β€œApples” documents!: /

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

Geocoding requests are limited in speed for each application, so running too many requests in a short amount of time may cause some requests to fail. When the maximum speed is exceeded, the geocoder passes the error object with a network of values ​​to your completion handler.

When checking the error code in the completion handler, this is really a network error: 2

Hope this helps someone!

+7
source

You rest CLGeocoder (). For example, I have a loop that checks an array of coordinates, if I, but CLGeocoder inside the loop, get the same error message as you.

Hope this helps.

-one
source

Source: https://habr.com/ru/post/1012552/


All Articles