Home > Back-end >  Does reverseGeocodeLocation(_ location: CLLocation) method works in offline mode?
Does reverseGeocodeLocation(_ location: CLLocation) method works in offline mode?

Time:12-16

I'm getting a location name from the method reverseGeocodeLocation(_ location: CLLocation). My requirement is along with storing Lat-Long values in DB in offline mode, I also want to store this location name string obtained from the above method. This is what I've implemented:

geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in
            
  let place = placemarks?[0]
  var countryName = ""
            
  if let countryString = place?.country {
       countryName = countryString
  }

I can definitely obtain lat-long in offline mode; my question is, does the above method work in offline mode too?

CodePudding user response:

As the documentation says (emphasis added):

This method submits the specified location data to the geocoding server asynchronously and returns.

Since it is sending the request to a server, you almost certainly will not be able to get the reverse geocode response if offline.

But you can add the coordinates to some persistent store, you should be able to reverse geocode them when you are back online. If you do this, though, remember that they are rate-limited. As the documentation goes on to say:

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 CLError.Code.network to your completion handler.

  • Related