Hi,
You can use this sample codes below, I checked Dynamics Client type (web - mobile) and if it's mobile I'm using directly Dynamics CRM client API.
Please call "getGeoLocation" in your function
getGeoLocation = function () {
var clientContext = Xrm.Utility.getGlobalContext().client;
var client = clientContext.getClient();
if (client == "Mobile") {
Xrm.Device.getCurrentPosition().then(
function success(position) {
updateLocationOnForm(position.coords.latitude, position.coords.longitude);
},
function (error) {
geolocationExceptionHandler(error);
}
);
}
else if (client == "Web") {
if (navigator.geolocation) {
var options = {
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(
function (position) {
updateLocationOnForm(position.coords.latitude, position.coords.longitude);
},
function (error) {
geolocationExceptionHandler(error);
},
options);
} else {
alert("No geo-location feature for this client");
}
}
else {
alert("No geo-location feature for this client");
}
};
updateLocationOnForm = function (lat, lon) {
Globals.Crm.setValue("rms_latitude", lat);
Globals.Crm.setValue("rms_longitude", lon);
Globals.Crm.saveForm();
};
geolocationExceptionHandler = function (error) {
switch (error.code) {
case error.PERMISSION_DENIED:
Globals.Crm.AlertDialog("EXCEPTION : \n('PERMISSION_DENIED')", null);
break;
case error.POSITION_UNAVAILABLE:
Globals.Crm.AlertDialog("EXCEPTION : \n('POSITION_UNAVAILABLE')", null);
break;
case error.TIMEOUT:
Globals.Crm.AlertDialog("EXCEPTION : \n('TIMEOUT')", null);
break;
case error.UNKNOWN_ERROR:
Globals.Crm.AlertDialog("EXCEPTION : \n('UNKNOWN_ERROR')", null);
break;
}
};