MobileLocation

From Xojo Documentation

Revision as of 19:47, 2 April 2021 by Gperlman (talk | contribs) (See Also)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Class (inherits from MobileControl)

New in 2020r2

The current location of the device.

Enumerations
Accuracies AuthorizationStates UsageTypes
Events
AuthorizationStateChanged LocationChanged
Closing Opening
Methods
Handle Start
RequestUsageAuthorization Stop
Properties
Accuracy AuthorizationState fa-lock-32.png Name

Notes

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

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

Sample plist

In addition to requesting authorization, you'll also need to provide a plist file specifying the message to display when authorization is requested. An example plist is below. Save it to a file called iOSLocation.plist and drag it into your iOS project to automatically include it with the app:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSLocationWhenInUseUsageDescription</key>
	<string>This app needs access to your location while running.</string>
</dict>
</plist>

See Also

CLLocationManager