Instance Method


Requests the one-time delivery of the user’s current location.


func requestLocation()


This method returns immediately. Calling it causes the location manager to obtain a location fix (which may take several seconds) and call the delegate’s locationManager(_:didUpdateLocations:) method with the result. The location fix is obtained at the accuracy level indicated by the desiredAccuracy property. Only one location fix is reported to the delegate, after which location services are stopped. If a location fix cannot be determined in a timely manner, the location manager calls the delegate’s locationManager(_:didFailWithError:) method instead and reports a locationUnknown error.

Use this method when you want the user’s current location but do not need to leave location services running. This method starts location services long enough to return a result or report an error and then stops them again. Calling the startUpdatingLocation() or allowDeferredLocationUpdates(untilTraveled:timeout:) method cancels any pending request made using this method. Calling this method while location services are already running does nothing. To cancel a pending request, call the stopUpdatingLocation() method.

If obtaining the desired accuracy would take too long, the location manager delivers a less accurate location value rather than reporting an error.

When using this method, the associated delegate must implement the locationManager(_:didUpdateLocations:) and locationManager(_:didFailWithError:) methods. Failure to do so is a programmer error.

See Also

Initiating Standard Location Updates

func startUpdatingLocation()

Starts the generation of updates that report the user’s current location.

func stopUpdatingLocation()

Stops the generation of location updates.

var pausesLocationUpdatesAutomatically: Bool

A Boolean value indicating whether the location manager object may pause location updates.

var allowsBackgroundLocationUpdates: Bool

A Boolean value indicating whether the app should receive location updates when suspended.

var distanceFilter: CLLocationDistance

The minimum distance (measured in meters) a device must move horizontally before an update event is generated.

var desiredAccuracy: CLLocationAccuracy

The accuracy of the location data.

var activityType: CLActivityType

The type of user activity associated with the location updates.

enum CLActivityType

Constants indicating the type of activity associated with location updates.