Core Location
Obtain the geographic location and orientation of a device.
Overview
Core Location provides services that determine a device’s geographic location, altitude, and orientation, or its position relative to a nearby iBeacon device. The framework gathers data using all available components on the device, including the Wi-Fi, GPS, Bluetooth, magnetometer, barometer, and cellular hardware.
You use instances of the CLLocationManager class to configure, start, and stop the Core Location services. A location manager object supports the following location-related activities:
- Standard and significant location updates
Track large or small changes in the user’s current location with a configurable degree of accuracy.
- Region monitoring
Monitor distinct regions of interest and generate location events when the user enters or leaves those regions.
- Beacon ranging
Detect and locate nearby beacons.
- Compass headings
Report heading changes from the onboard compass.
To use location services, call liveUpdates(_:) to obtain an update stream, then asynchronously iterate over that stream to receive and process location updates, and receive diagnostic properties to understand if and why location updates don’t arrive.
If needed, the system prompts the user to grant or deny the request. An initial prompt is shown in the example below:
[Image]
On iOS devices, users can change location service settings at any time in the Settings app, affecting individual apps or the device as a whole. Your app receives events, including authorization changes, by observing asynchronous sequences from CLLocationUpdate and CLMonitor.
Topics
Essentials
Configuring your app to use location servicesSupporting live updates in SwiftUI and Mac Catalyst appsCLLocationManagerCLBackgroundActivitySessionCLLocationUpdateAdopting live updates in Core LocationMonitoring location changes with Core Location
Authorization
Requesting authorization to use location servicesSuspending authorization requestsCLAuthorizationStatusCLAccuracyAuthorizationNSLocationAlwaysAndWhenInUseUsageDescriptionNSLocationWhenInUseUsageDescriptionNSLocationUsageDescriptionNSLocationDefaultAccuracyReducedNSLocationAlwaysUsageDescription
Monitoring
Location updates
Getting the current location of a deviceHandling location updates in the backgroundCreating a location push service extensionCLLocationCLLocationCoordinate2DCLFloorCLVisitCLLocationSourceInformationMonitoring location changes with Core LocationCLServiceSession
Region monitoring
iBeacon
Ranging for BeaconsDetermining the proximity to an iBeacon deviceTurning an iOS device into an iBeacon deviceCLBeaconCLCondition
Compass headings
Geocoding
Converting between coordinates and user-friendly place namesConverting a user’s location to a descriptive placemarkCLGeocoderCLPlacemark
Location push service extension
Location Push Service ExtensionCLLocationPushServiceExtensionCLLocationPushServiceErrorCLLocationPushServiceErrorDomainCLLocationPushServiceError.Code