Fetching the Current Location

When the user taps the button to add the geofence, our app has to fetch the current location and start to monitor a region around that location. Add the following method to LocationProvider to request the current location:

 func​ ​setHome​() {
  locationManager.​requestLocation​()
 }

The method requestLocation requests the current location of the device and then stops location updates. This method is a perfect fit if you need a location only once instead of continually. The locationManager delivers the result to its delegate through the delegate method locationManager(_:didUpdateLocations:). Add the following method to LocationProvider:

Get Build Location-Based Projects for iOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.