getCurrentPosition (Client API reference)
Returns the current location using the device geolocation capability.
Available for
This method is supported only for the mobile clients.
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 values is passed to the function.: - coords : Contains a set of geographic coordinates along with associated accuracy as well as a set of other optional values 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 values specified earlier in the successCallback function.
Exceptions
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.
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 });
}
);
Related articles
意見反映
https://aka.ms/ContentUserFeedback。
即將推出:我們會在 2024 年淘汰 GitHub 問題,並以全新的意見反應系統取代並作為內容意見反應的渠道。 如需更多資訊,請參閱:提交及檢視以下的意見反映: