Class
LocationManager
public final class LocationManager: NSObject, CLLocationManagerDelegate
A general LocationManger
Relationships
Nested Types
LocationManager.Errors
Errors that can occur in the LocationManager.
Conforms To
CLLocationManagerDelegate
NSObject
Properties
currentLocation
public var currentLocation: CLLocation?
The most recently retrieved user location.
The value of this property is nil if no location data has ever been retrieved. In iOS 4.0 and later, this property may contain a more recent location object at launch time. Specifically, if significant location updates are running and your app is terminated, this property is updated with the most recent location data when your app is relaunched (and you create a new location manager object). This location data may be more recent than the last location event processed by your app. It is always a good idea to check the timestamp of the location stored in this property. If the receiver is currently gathering location data, but the minimum distance filter is large, the returned location might be relatively old. If it is, you can stop the receiver and start it again to force an update.
Methods
requestWhenInUseAuthorization()
public func requestWhenInUseAuthorization()
Ask the manager to request whenInUse authorization from the user.
requestAlwaysAuthorization()
public func requestAlwaysAuthorization()
Ask the manager to request always authorization from the user.
requestWhenInUseAuthorizationIfNeeded()
public func requestWhenInUseAuthorizationIfNeeded()
Ask the manager to request whenInUse authorization from the user if needed.
fetchCurrentLocation(desiredAccuracy:completion:)
public func fetchCurrentLocation(
desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest,
completion: @escaping (_ result: Result<CLLocation, Errors>) -> Void
)
Askes the manager to fetch the users current location.
Parameters
Name | Type | Description |
---|---|---|
desiredAccuracy | CLLocationAccuracy |
The desired accuracy of the location. Defaults to kCLLocationAccuracyBest. |
completion | @escaping (_ result: Result<CLLocation, Errors>) -> Void |
The closure that will be called with the Result of the request. |
result | The Result of the request. |
locationManager(_:didChangeAuthorization:)
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)
locationManager(_:didUpdateLocations:)
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
locationManager(_:didFailWithError:)
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error)