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
Advertisements

2 responses to “Dynamics 365 Mobile Client – Script to get Longitude and Latitude and pin to Maps”

  1. Gayatri Avatar
    Gayatri

    Hi Rajeev,

    How to get auto generated number sequence for a Expense ID in power app.

    Steps followed :
    1. in D365 created a custom data entity , using table TRVexepnse.
    2. Logged to Power app, created a app using data connection as Dynamics 365 for operations and selected the custom data entity.
    3. I got 3 screen in the app, browse, detailed and edit screens.
    4. While adding new record through app, Expense ID should generate automatically. (App showing error saying Expene no is mandatory)
    5. In APP, Expense field is read only.

    Please suggest how to over come this issue.

    Regards,
    Gayatri

  2. Aayush Avatar
    Aayush

    But HTML doesn’t works on Phone..An above doesn’t works on web…So basically We can only use it for tablet or is there any way to view it either on web or mobile?

Leave a comment