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 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기