0

I am trying to get address of location through reverseGeocodeLocation but sometimes it returns nil address, what I want is get nearby address if reverseGeocodeLocation returns nil address for any particular location.

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)
        }
    }
Varun Naharia
  • 5,318
  • 10
  • 50
  • 84

1 Answers1

1

You may be hitting the limit of geocoder.

Excerpt from the 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.

Juri Noga
  • 4,363
  • 7
  • 38
  • 51
  • I am not getting error it's just location has no address, I am only requesting `reverseGeocodeLocation` when location did change – Varun Naharia Apr 10 '17 at 08:36