Class

iOSLocation


Warning

This item was deprecated in version 2020r2. Please use MobileLocation as a replacement.

Description

An iOSLocation allows the user to request location coordinates and updates from the device.

Properties

Name

Type

Read-Only

Shared

Accuracy

Accuracies

AuthorizationState

AuthorizationStates

Enabled

Boolean

Handle

Ptr

Methods

Name

Parameters

Returns

Shared

RequestAlwaysAuthorization

RequestInUseAuthorization

Events

Name

Parameters

Returns

AuthorizationChanged

LocationChanged

latitude As Double, longitude As Double, accuracy As Double, altitude As Double, altitudeAccuracy As Double, course As Double, speed As Double

Enumerations

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.

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


iOSLocation.Accuracy

Accuracy As 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.

MyLocation.Accuracy = iOSLocation.Accuracies.Kilometer

iOSLocation.AuthorizationState

AuthorizationState As AuthorizationStates

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

This property is read-only.


iOSLocation.Enabled

Enabled As 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:

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

iOSLocation.Handle

Handle As Ptr

The underlying CLLocationManager for use by Declares.

This property is read-only.

Method descriptions


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.

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

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.

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


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:

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

iOSLocation.LocationChanged

LocationChanged(latitude As Double, longitude As Double, accuracy As Double, altitude As Double, altitudeAccuracy As Double, course As Double, speed As Double)

Called when a location update is received from iOS.

Display some of the location values in labels:

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:

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.