CLLocationManager
The object you use to start and stop the delivery of location-related events to your app.
Declaration
class CLLocationManagerMentioned in
- Determining the proximity to an iBeacon device
- Configuring your app to use location services
- Converting between coordinates and user-friendly place names
- Getting heading and course information
- Getting the current location of a device
- Requesting authorization to use location services
- Monitoring the user’s proximity to geographic regions
- Supporting live updates in SwiftUI and Mac Catalyst apps
Overview
A CLLocationManager object is the central place to manage your app’s location-related behaviors. Use a location-manager object to configure, start, and stop location services. You might use these services to:
Track large or small changes in the user’s current location with a configurable degree of accuracy.
Report heading changes from the onboard compass.
Monitor geographical regions of interest and generate events when someone enters or leaves those regions.
Report the range to nearby Bluetooth beacons.
Create one or more location-manager objects in your app and use them where you need location data. After you create a location-manager object, configure it so that Core Location knows how often to report location changes. In particular, configure the distanceFilter and desiredAccuracy properties with values that reflect your app’s needs.
A CLLocationManager object reports all location-related updates to its delegate object, which is an object that conforms to the CLLocationManagerDelegate protocol. Assign the delegate immediately when you configure your location manager, because the system reports the app’s authorization status to the delegate’s locationManagerDidChangeAuthorization(_:) method after the location manager finishes initializing itself. Core Location calls the methods of your delegate object using the RunLoop of the thread on which you initialized the CLLocationManager object. That thread must itself have an active RunLoop, like the one found in your app’s main thread.
For more information, see Configuring your app to use location services.
Topics
Determining the availability of services
significantLocationChangeMonitoringAvailable()headingAvailable()isAuthorizedForWidgetUpdatesaccuracyAuthorizationisMonitoringAvailable(for:)isRangingAvailable()locationServicesEnabled()
Receiving data from location services
Requesting authorization for location services
requestWhenInUseAuthorization()requestAlwaysAuthorization()requestTemporaryFullAccuracyAuthorization(withPurposeKey:completion:)requestTemporaryFullAccuracyAuthorization(withPurposeKey:)authorizationStatusCLAuthorizationStatusNSLocationDefaultAccuracyReducedNSLocationAlwaysAndWhenInUseUsageDescription
Specifying distance and accuracy
distanceFilterCLLocationDistanceMaxkCLDistanceFilterNoneCLLocationDistancedesiredAccuracyCLLocationAccuracy
Running the standard location service
startUpdatingLocation()stopUpdatingLocation()requestLocation()pausesLocationUpdatesAutomaticallyallowsBackgroundLocationUpdatesshowsBackgroundLocationIndicatoractivityTypeCLActivityType
Running the significant change location service
Running the visits location service
Running the heading service
startUpdatingHeading()stopUpdatingHeading()dismissHeadingCalibrationDisplay()headingFilterkCLHeadingFilterNoneCLLocationDegreesheadingOrientationCLDeviceOrientation