Class

MobileLocation


Description

The current location of the device.

Properties

Name

Type

Read-Only

Shared

Accuracy

Accuracies

AuthorizationState

AuthorizationStates

Name

String

Methods

Name

Parameters

Returns

Shared

Handle

Ptr

RequestUsageAuthorization

usageType As MobileLocation.UsageTypes

Start

Stop

Events

Name

Parameters

Returns

AuthorizationStateChanged

state As MobileLocation.AuthorizationStates

Closing

LocationChanged

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

Opening

Enumerations

MobileLocation.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.

Within10Meters

Accurate to within 10 meters of the desired target.

Within100Meters

Accurate to within 100 meters.

Within1Kilometer

Accurate to within 1 kilometer.

Within3Kilometers

Accurate to within 3 kilometers.

MobileLocation.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.

AuthorizedAppInUse

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.

MobileLocation.UsageTypes

UsageTypes

Used to indicate when your app will need access to the device's location.

Enum

Description

Always

You are requesting that the OS update your app on the device's location any time it changes.

AppInUse

You are requesting that the OS update your app on the device's location only when your app is in the foreground.

Property descriptions


MobileLocation.Accuracy

Accuracy As Accuracies

Specifies the level of accuracy you need for the location data.

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

MyLocation.Accuracy = MobileLocation.Accuracies.Within1Kilometer

MobileLocation.AuthorizationState

AuthorizationState As AuthorizationStates

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

This property is read-only.


MobileLocation.Name

Name As String

The name of the control.

Method descriptions


MobileLocation.Handle

Handle As Ptr

The a handle to the underlying native OS control.


MobileLocation.RequestUsageAuthorization

RequestUsageAuthorization(usageType As MobileLocation.UsageTypes)

Request authorization for this app to use location information.

You can request authorization to obtain the device's location either only while your app is in use or at all times. See the AuthorizationStates enumeration for details.

If myLocation.AuthorizationState = MobileLocation.AuthorizationStates.AuthorizedAppInUse 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.RequestUsageAuthorization(MobileLocation.UsageTypes.AppInUse)
End If

MobileLocation.Start

Start

Start receiving location information.

This causes the LocationChanged event to be called.


MobileLocation.Stop

Stop

Stops receiving location information.

Event descriptions


MobileLocation.AuthorizationStateChanged

AuthorizationStateChanged(state As MobileLocation.AuthorizationStates)

Called when the authorization state changes.


MobileLocation.Closing

Closing

Called when the control's layout is closing.


MobileLocation.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 the OS.

Display some of the location values in labels:

LatitudeLabel.Text = latitude.ToString
LongitudeLabel.Text = longitude.ToString
SpeedLabel.Text = speed.ToString

MobileLocation.Opening

Opening

Called when the control's layout is opening.

This is where you typically put initialization code.

This example in the Opening event of a label sets its text to "Hello":

Me.Text = "Hello"

Notes

On iOS to test this in the Simulator, use the Debug > Location menu to provide fake locations.

To use this class you must enable the Location entitlement.


Initial setup

In the Opening event handler of the screen, you will need to initialize the location like this:

If MyLocation.AuthorizationState = MobileLocation.AuthorizationStates.AuthorizedAppInUse Then
  ' we've got our requested authorization state, start getting LocationChanged events
  MyLocation.Start
Else
  ' we don't have authorization yet, so ask for it
  MyLocation.RequestUsageAuthorization(MobileLocation.UsageTypes.AppInUse)
End If

Compatibility

Mobile projects on all supported mobile operating systems.

See also

MobileControl parent class; CLLocationManager