Instance Method

requestLocation

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

Declaration

- (void)requestLocation;

Discussion

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 kCLErrorLocationUnknown 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 allowDeferredLocationUpdatesUntilTraveled: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

- startUpdatingLocation

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

- stopUpdatingLocation

Stops the generation of location updates.

pausesLocationUpdatesAutomatically

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

allowsBackgroundLocationUpdates

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

showsBackgroundLocationIndicator

A Boolean indicating whether the status bar changes its appearance when an app uses location services in the background.

distanceFilter

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

CLLocationDistanceMax

A constant indicating the maximum distance.

kCLDistanceFilterNone

A constant indicating that all movement should be reported.

desiredAccuracy

The accuracy of the location data.

activityType

The type of user activity associated with the location updates.

CLActivityType

Constants indicating the type of activity associated with location updates.