UserGuide

iOS 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 iOSLocation in the Language Reference for the complete list.

Events

LocationChanged

Called when a location update is received from iOS.

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

RequestAlwaysAuthorization

Request approval to use the location at any time.

RequestInUseAuthorization

Requests approval to use location when the app is active.

Usage

Before you can get the location you must request authorization. This is typically done 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

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

See Also

iOSLocation class; UserGuide:iOS UI topic