<div class="meta" robots="noindex">

</div>

Class

# iOSLocation

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r2. Please use `MobileLocation</api/mobile/mobilelocation>` as a replacement.

</div>

## Description

An <span class="title-ref">iOSLocation</span> allows the user to request location coordinates and updates from the device.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                 | Type                                                   | Read-Only | Shared |
|------------------------------------------------------|--------------------------------------------------------|-----------|--------|
| `Accuracy<ioslocation.accuracy>`                     | `Accuracies<ioslocation.accuracies>`                   |           |        |
| `AuthorizationState<ioslocation.authorizationstate>` | `AuthorizationStates<ioslocation.authorizationstates>` | ✓         |        |
| `Enabled<ioslocation.enabled>`                       | `Boolean</api/data_types/boolean>`                     |           |        |
| `Handle<ioslocation.handle>`                         | `Ptr</api/data_types/additional_types/ptr>`            | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                                 | Parameters | Returns | Shared |
|----------------------------------------------------------------------|------------|---------|--------|
| `RequestAlwaysAuthorization<ioslocation.requestalwaysauthorization>` |            |         |        |
| `RequestInUseAuthorization<ioslocation.requestinuseauthorization>`   |            |         |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                     | Parameters                                                                                                                                                                                                                                                                                                                           | Returns |
|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `AuthorizationChanged<ioslocation.authorizationchanged>` |                                                                                                                                                                                                                                                                                                                                      |         |
| `LocationChanged<ioslocation.locationchanged>`           | latitude As `Double</api/data_types/double>`, longitude As `Double</api/data_types/double>`, accuracy As `Double</api/data_types/double>`, altitude As `Double</api/data_types/double>`, altitudeAccuracy As `Double</api/data_types/double>`, course As `Double</api/data_types/double>`, speed As `Double</api/data_types/double>` |         |

## Enumerations

<div id="ioslocation.accuracies">

<div class="rst-class">

forsearch

</div>

</div>

iOSLocation.Accuracies

### Accuracies

The available degrees of accuracy to track. Used by the Accuracy property.

| Enum              | Description                                                                                                                                                                                                                                                                 |
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| BestForNavigation | Use the highest possible accuracy and combine it with additional sensor data. This level of accuracy is intended for use in navigation applications that require precise position information at all times and are intended to be used only while the device is plugged in. |
| Best              | (Default) Use the highest-level of accuracy.                                                                                                                                                                                                                                |
| NearestTenMeters  | Accurate to within ten meters of the desired target.                                                                                                                                                                                                                        |
| HundredMeters     | Accurate to within one hundred meters.                                                                                                                                                                                                                                      |
| Kilometer         | Accurate to the nearest kilometer.                                                                                                                                                                                                                                          |
| ThreeKilometers   | Accurate to the nearest three kilometers.                                                                                                                                                                                                                                   |

<div id="ioslocation.authorizationstates">

<div class="rst-class">

forsearch

</div>

</div>

iOSLocation.AuthorizationStates

### AuthorizationStates

These are the available authorization states for an app. The AuthorizationState property contains the type of location the user has authorized.

| Enum                | Description                                                                                                                                                                                                                                                           |
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| NotDetermined       | The user has not yet made a choice regarding whether this app can use location services.                                                                                                                                                                              |
| Restricted          | This app is not authorized to use location services. The user cannot change this app's status, possibly due to active restrictions such as parental controls being in place.                                                                                          |
| Denied              | The user explicitly denied the use of location services for this app or location services are currently disabled in Settings.                                                                                                                                         |
| AuthorizedAlways    | This app is authorized to start location services at any time. This authorization allows you to use all location services, including those for monitoring regions and significant location changes.                                                                   |
| AuthorizedWhenInUse | This app is authorized to start most location services while running in the foreground. This authorization does not allow you to use APIs that could launch your app in response to an event, such as region monitoring and the significant location change services. |

## Property descriptions

<div id="ioslocation.accuracy">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.Accuracy

**Accuracy** As `Accuracies<ioslocation.accuracies>`

Specifies the level of accuracy you need for the location data. Default is Accuracies.Best. Greater accuracy generally uses more battery power.

You should assign a value to this property that is appropriate for your usage scenario. For example, if you need the current location only within a kilometer, you should specify Accuracies.Kilometer and not Accuracies.BestForNavigation. Determining a location with greater accuracy requires more time and more power.

``` xojo
MyLocation.Accuracy = iOSLocation.Accuracies.Kilometer
```

<div id="ioslocation.authorizationstate">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.AuthorizationState

**AuthorizationState** As `AuthorizationStates<ioslocation.authorizationstates>`

Returns the app's authorization state for using location services.

This property is read-only.

<div id="ioslocation.enabled">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.Enabled

**Enabled** As `Boolean</api/data_types/boolean>`

Default is False. Set Enabled to True so that the LocationChanged event is called at appropriate times. Set this to False when you do not need locations in order to not waste battery power.

Do not enable if AuthorizationState is AuthorizationStates.Restricted or AuthorizationStates.Denied.

You will typically use code like this in the Open event handler of your view to initialize \`iOSLocation\`:

``` xojo
If MyLocation.AuthorizationState = iOSLocation.AuthorizationStates.AuthorizedWhenInUse Then
  ' we've got our requested authorization state, start getting LocationChanged events
  MyLocation.Enabled = True
Else
  ' we don't have authorization yet, so ask for it
  MyLocation.RequestInUseAuthorization
End If
```

<div id="ioslocation.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

The underlying CLLocationManager for use by Declares.

This property is read-only.

## Method descriptions

<div id="ioslocation.requestalwaysauthorization">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.RequestAlwaysAuthorization

**RequestAlwaysAuthorization**

Request authorization for this app to use location information at any time.

This requires the plist key "NSLocationAlwaysUsageDescription" of the app to be populated.

``` xojo
If myLocation.AuthorizationState = iOSLocation.AuthorizationStates.AuthorizedWhenInUse Then
  ' we've got our requested authorization state, start getting LocationChanged events
  MyLocation.Enabled = True
Else
  ' we don't have authorization yet, so ask for it
  MyLocation.RequestInUseAuthorization
End If
```

<div id="ioslocation.requestinuseauthorization">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.RequestInUseAuthorization

**RequestInUseAuthorization**

Request authorization for this app to use location information only when it is active.

This requires the plist key "NSLocationWhenInUseUsageDescription" of the app to be populated.

``` xojo
If myLocation.AuthorizationState = iOSLocation.AuthorizationStates.AuthorizedWhenInUse Then
  ' we've got our requested authorization state, start getting LocationChanged events
  MyLocation.Enabled = True
Else
  ' we don't have authorization yet, so ask for it
  MyLocation.RequestInUseAuthorization
End If
```

## Event descriptions

<div id="ioslocation.authorizationchanged">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.AuthorizationChanged

**AuthorizationChanged**

Called when the app's authorization to location services has changed. You can check the AuthorizationState property to see the new state.

This code enables the control so it gets events when the location changes:

``` xojo
If Me.AuthorizationState = iOSLocation.AuthorizationStates.AuthorizedWhenInUse Then
  ' start getting LocationChanged events
  Me.Enabled = True
End If
```

<div id="ioslocation.locationchanged">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

iOSLocation.LocationChanged

**LocationChanged**(latitude As `Double</api/data_types/double>`, longitude As `Double</api/data_types/double>`, accuracy As `Double</api/data_types/double>`, altitude As `Double</api/data_types/double>`, altitudeAccuracy As `Double</api/data_types/double>`, course As `Double</api/data_types/double>`, speed As `Double</api/data_types/double>`)

Called when a location update is received from iOS.

Display some of the location values in labels:

``` xojo
LatitudeLabel.Text = latitude.ToText
LongitudeLabel.Text = longitude.ToText
SpeedLabel.Text = speed.ToText
```

## Notes

Use the Debug \> Location menu in the iOS Simulator to provide fake locations for testing.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Initial setup

In the Open event handler of the view, you will need to initialize the location like this:

``` xojo
If MyLocation.AuthorizationState = iOSLocation.AuthorizationStates.AuthorizedWhenInUse Then
  ' we've got our requested authorization state, start getting LocationChanged events
  MyLocation.Enabled = True
Else
  ' we don't have authorization yet, so ask for it
  MyLocation.RequestInUseAuthorization
End If
```

## Compatibility

iOS projects on the iOS operating system.

## See also

`Object</api/data_types/additional_types/object>` parent class; \[CLLocationManager <https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/>\]
