Advertisements

Archive

Archive for January 14, 2017

Dynamics 365 Mobile Client – Script to get Longitude and Latitude and pin to Maps

January 14, 2017 2 comments

With the new Dynamics 365 Mobile client, we got a new API Xrm.Utility.getCurrentPosition which returns the current location coordinates.

This API only works with Mobile Client and referring this in Web Application would cause script error.

Pre-requisite:

We need to Enable User Location setting on the device

  • Go to Settings -> Device Integration Settings
Device-integration-settings

Device-integration-settings

  • Enable “User Content and Location”
Enable-user-location

Enable-user-location

Script to get coordinates:

function onload() {
var isCrmForMobile = (Xrm.Page.context.client.getClient() == “Mobile”);

if (isCrmForMobile) {
Xrm.Utility.getCurrentPosition().then
(function (location) {
Xrm.Utility.alertDialog(“Latitude: ” + location.coords.latitude +
“, Longitude: ” + location.coords.longitude);
},
function (error) {
Xrm.Utility.alertDialog(error.message);
})
}
}

Get-longitude-and-latitude

Get-longitude-and-latitude

HTML File to Read Coordinates and Show in Map

html-show-location-on-map

🙂

Advertisements