getCurrentPosition (Client API reference)

Returns the current location using the device geolocation capability.

Syntax

Xrm.Device.getCurrentPosition().then(successCallback, errorCallback)

Parameters

Parameter Name Type Required Description
successCallback Function Yes A function to call when the current geolocation information is returned. A geolocation object with the following attributes is passed to the function.:
- coords: Contains a set of geographic coordinates along with associated accuracy as well as a set of other optional attributes such as altitude and speed.
- timestamp: Represents the time when the object was acquired and is represented as DOMTimeStamp.
errorCallback Function Yes A function to call when the operation fails. An object with the following properties will be passed:
- code: The error code. Number.
- message: RLocalized message describing the error details. String.

If the user location setting is not enabled on your mobile device, the error message indicates the same. If you are using an earlier version of the model-driven apps mobile client or if geolocation capability is not available on your mobile device, null is passed to the error callback.

Return Value

On success, returns a geolocation object with the attributes specified earlier in the successCallback function.

Remarks

For the getCurrentPosition method to work, the geolocation capability must be enabled on your mobile device, and the model-driven apps mobile clients must have permissions to access the device location, which isn't enabled by default.

This method is supported only for the mobile clients.

Example

Xrm.Device.getCurrentPosition().then(
    function success(location) {
        Xrm.Navigation.openAlertDialog({
            text: "Latitude: " + location.coords.latitude +
            ", Longitude: " + location.coords.longitude
        });
    },
    function (error) {
        Xrm.Navigation.openAlertDialog({ text: error.message });
    }
);

Xrm.Device