Class

MobileLocation


Description

The current location of the device.

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

RegionEntered

region As MobileCircularRegion

RegionExited

region As MobileCircularRegion

VisitChanged

latitude As Double, longitude As Double, accuracy As Double, arrival As DateTime, departure As DateTime

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.

Reduced

Infrequent location change updates to greatly preserve battery life.

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

AllowBackgroundUpdates As Boolean

Allows the location to be updated by the OS even when the application is not the frontmost application.

Important

This property is not currently supported for Android.


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.


MobileLocation.VisitAwareness

VisitAwareness As Boolean

Tells the device to begin tracking arrivals and departures from locations.

This is a power-efficient way to track user location.

Important

This property is not currently supported for Android.

Method descriptions


MobileLocation.AddRegion

AddRegion(region As MobileCircularRegion)

Adds the region passed to the list of regions to be monitored for user entry and exit.

Important

This property is not currently supported for Android.


MobileLocation.AddRegion

AddRegion(index As Integer, region As MobileCircularRegion)

Adds the region passed at the index passed to the list of regions to be monitored for user entry and exit.

Important

This property is not currently supported for Android.


MobileLocation.AddAllRegions

AddAllRegions(regions() As MobileCircularRegion)

Adds all regions in the array of regions passed to the list of regions to be monitored for user entry and exit.

Important

This property is not currently supported for Android.


MobileLocation.Handle

Handle As Ptr

The handle to the underlying native OS control.

Important

This method is supported for iOS only.


MobileLocation.RegionAt

RegionAt(index As Integer) As MobileCircularRegion

Returns the region at the index passed.

Important

This property is not currently supported for Android.


MobileLocation.Regions

Regions As MobileCircularRegion()

Returns an array of all regions that have been added.

Important

This property is not currently supported for Android.


MobileLocation.RemoveRegion

RemoveRegion(region As MobileCircularRegion)

Removes the region passed from the list of regions to be monitored for user entry and exit.

Important

This property is not currently supported for Android.


MobileLocation.RemoveRegionAt

RemoveRegionAt(index As Integer)

Removes the region at the index passed from the list of regions to be monitored for user entry and exit.

Important

This property is not currently supported for Android.


MobileLocation.RemoveAllRegions

RemoveAllRegions

Removes all regions from the list of regions to be monitored for user entry and exit.

Important

This property is not currently supported for Android.


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.Start
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"

MobileLocation.RegionEntered

RegionEntered(region As MobileCircularRegion)

Called when the user enters a previously defined region.

Important

This property is not currently supported for Android.


MobileLocation.RegionExited

RegionExited(region As MobileCircularRegion)

Called when the user exits a previously defined region.

Important

This property is not currently supported for Android.


MobileLocation.VisitChanged

VisitChanged(latitude As Double, longitude As Double, accuracy As Double, arrival As DateTime, departure As DateTime)

The user has either arrived at a new location or departed from their current location.

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