CLLocationManager Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Manages the delivery of location, region, and heading events to your application.
[Foundation.Register("CLLocationManager", true)]
public class CLLocationManager : Foundation.NSObject
[<Foundation.Register("CLLocationManager", true)>]
type CLLocationManager = class
inherit NSObject
- Inheritance
- Attributes
Remarks
Requesting Authorization
Developers that want to request access to the location information must request permission from the user to do so before they can receive events. This is done by calling either the RequestWhenInUseAuthorization() method. When these methods are invoked, the system will prompt the user for authorization, and if he grants it, the AuthorizationChanged event will be raised if set (or if you are using the Delegate idiom, the AuthorizationChanged(CLLocationManager, CLAuthorizationStatus) method will be invoked.
Additionally, developers must add one or both of the keys NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription in their app's info.plist. These keys are strings that can be used to describe why the app needs location access.
Developers should use an idiom like this:
var manager = new CLLocationManager();
manager.AuthorizationChanged += (sender, args) => {
Console.WriteLine ("Authorization changed to: {0}", args.Status);
};
if (UIDevice.CurrentDevice.CheckSystemVersion(8,0))
manager.RequestWhenInUseAuthorization();
Tracking the device's location
The most common use-case for the CLLocationManager is tracking the device while the application is in the foreground. (See also "Background Updating and Deferred Mode" below.)
Application developers may use either C#-style events or Apple's delegate-object pattern to track foreground location updating. For C#-style events, developers can use the LocationsUpdated event:
var mgr = new CLLocationManager();
mgr.LocationsUpdated += (sender, e) => {
foreach(var loc in e.Locations)
{
Console.WriteLine(loc);
}
};
mgr.StartUpdatingLocation();
let mgr = new CLLocationManager()
mgr.LocationsUpdated.Add( fun e ->
e.Locations |> Seq.map Console.WriteLine |> ignore )
mgr.StartUpdatingLocations()
While C#-style events are more concise, the CLLocationManager must use the delegate-object pattern for certain behaviors (for instance, deferred updating), and it may be more consistent for an application to use the delegate-object pattern even when C#-style events are available. The delegate-object pattern consists of assigning a customized CLLocationManagerDelegate object to the Delegate property of the CLLocationManager:
var mgr = new CLLocationManager();
mgr.Delegate = new MyLocationDelegate();
mgr.StartUpdatingLocation();
//...etc...
public class MyLocationDelegate : CLLocationManagerDelegate {
public override void LocationsUpdated (CLLocationManager manager, CLLocation[] locations) {
foreach(var loc in locations) {
Console.WriteLine(loc);
}
}
}
let mgr = new CLLocationManager()
mgr.Delegate <- new MyLocationDelegate()
mgr.StartUpdatingLocation()
//...etc...
type MyLocationDelegate () = inherit CLLocationManagerDelegate()
override this.LocationsUpdated ( manager : CLLocationManager, locations : CLLocation[] ) =
locations
|> Seq.map Console.WriteLine
|> ignore
Background Updating and Deferred Mode
Locations can be updated while the application is in the background. This requires that the info.plist be modified using either Xamarin Studio's visual editor:

Or by adding the key manually:
<example>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
</example> </block> <block subset="none" type="behaviors">
Importance of Delegate object
Generally, when using Xamarin.iOS, developers can freely choose whether to use C# events or Apple-style "delegate objects" to react to object lifecycle events. Several CLLocationManager methods, however, require the delegate-object pattern.
</block>
Constructors
| Name | Description |
|---|---|
| CLLocationManager() |
Creates a new CLLocationManager with default values. |
| CLLocationManager(NativeHandle) |
A constructor used when creating managed representations of unmanaged objects. Called by the runtime. |
| CLLocationManager(NSObjectFlag) |
Constructor to call on derived classes to skip initialization and merely allocate the object. |
Properties
| Name | Description |
|---|---|
| AccessibilityAttributedUserInputLabels | (Inherited from NSObject) |
| AccessibilityRespondsToUserInteraction | (Inherited from NSObject) |
| AccessibilityTextualContext | (Inherited from NSObject) |
| AccessibilityUserInputLabels | (Inherited from NSObject) |
| AccuracyAuthorization | |
| ActivityType |
Used to provide the operating system clues for better power consumption / accuracy. |
| AllowsBackgroundLocationUpdates |
Gets or sets a Boolean value that controls whether the application will respond to location updates while it is suspended. |
| AuthorizationStatus | |
| Class | (Inherited from NSObject) |
| ClassHandle |
The Objective-C class handle for this class. |
| DebugDescription | (Inherited from NSObject) |
| DeferredLocationUpdatesAvailable |
Whether background-generated deferred location data are available. |
| Delegate |
An instance of the CoreLocation.ICLLocationManagerDelegate model class which acts as the class delegate. |
| Description | (Inherited from NSObject) |
| DesiredAccuracy |
The accuracy preferred by the app. (Coarser accuracies consume less power.) |
| DistanceFilter |
The minimum horizontal distance, in meters, the device has to move before issuing a location update. |
| ExposedBindings | (Inherited from NSObject) |
| Handle |
Handle (pointer) to the unmanaged object representation. (Inherited from NSObject) |
| Heading |
The most recent heading (direction in which the device is traveling). |
| HeadingAvailable |
Whether the Heading property is not |
| HeadingFilter |
The minimum change in heading, in degreees, necessary to generate a location update. |
| HeadingOrientation |
The orientation used to determine heading calculations. |
| IsAuthorizedForWidgetUpdates | |
| IsDirectBinding | (Inherited from NSObject) |
| IsProxy | (Inherited from NSObject) |
| IsRangingAvailable |
Gets a Boolean value that tells whether the device can range Bluetooth beacons. |
| Location |
The most recently-retrieved CLLocation. |
| LocationServicesEnabled |
Whether location services are available. |
| MaximumRegionMonitoringDistance |
The largest boundary distance, in meters, that can be assigned to a region. |
| MaxTimeInterval |
Represents the value associated with the constant CLTimeInternalMax |
| MonitoredRegions |
The set of CLRegions being monitored by the app. |
| PausesLocationUpdatesAutomatically |
Whether the system is allowed to pause location updates (for instance, if the device has not moved in awhile). |
| Purpose |
Developers should not use this deprecated property. |
| RangedBeaconConstraints | |
| RangedRegions |
The set of CLRegions being tracked using ranging. |
| RegionMonitoringAvailable |
Application developers should use IsMonitoringAvailable(Type) rather than this deprecated method. |
| RegionMonitoringEnabled |
Application developers should use IsMonitoringAvailable(Type) rather than this deprecated method. |
| RetainCount | (Inherited from NSObject) |
| Self | (Inherited from NSObject) |
| ShouldDisplayHeadingCalibration | |
| ShowsBackgroundLocationIndicator | |
| SignificantLocationChangeMonitoringAvailable |
Whether "significant location change" monitoring (e.g., via cell tower switch) is available. |
| Status |
The authorization status of the app (e.g., if the app is denied access to location services). |
| Superclass | (Inherited from NSObject) |
| SuperHandle |
Handle used to represent the methods in the base class for this NSObject. (Inherited from NSObject) |
| WeakDelegate |
An object that can respond to the delegate protocol for this type |
| Zone | (Inherited from NSObject) |