UserGuide

Mobile Location

From Xojo Documentation

The Location control provides a way for you to get location information for the device. This is not a visual control, so dragging it appears on the Shelf when dragged to the layout.

Use the Debug ↠ Location menu in the iOS Simulator to provide locations for testing.

Frequently getting the location can cause significant battery drain, so only be sure to set Enabled = False when it is not needed.

iOS Location Library Icon

Below is a list of commonly used events, properties and methods. Refer to MobileLocation in the Language Reference for the complete list.

Events

LocationChanged

Called when a location update is received from the OS.

Properties

Accuracy

Specifies the level of accuracy for the location using the Accuracies enum. The "Best" accuracy is used by default, but you can increase or decrease the accuracy as necessary to manage battery usage.

AuthorizationState

Indicates the level of authorization that is allowed for location. Check this before enabling.

Enabled

When enabled is True, the LocationChanged event is called with location updates. You should set this to False when the location is not needed.

Methods

RequestUsageAuthorization

Requests approval to use location either always or when the app is in use.

Usage

Before you can get the location you must request authorization. This is typically done like this:

If MyLocation.AuthorizationState = MobileLocation.AuthorizationStates.AppInUse 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
End If

Once the control is enabled you will start getting LocationChanged events when the location is updated.

See Also

MobileLocation class; UserGuide:iOS User Interface Controls topic