getCurrentPosition (Client API reference)

Applies to Dynamics 365 for Customer Engagement apps version 9.x

Returns the current location using the device geolocation capability.


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


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 Dynamics 365 for Customer Engagement 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.


For the getCurrentPosition method to work, the geolocation capability must be enabled on your mobile device, and the Dynamics 365 for Customer Engagement 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.


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