How to detect location (Longitude and latitude) from PC or Laptop to save this information into CRM record using Plugin or JS code.
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; } };
Hi partner,
You could use Html5 Geolocation to detect your location in real time and then add the Js code into the form.
Here is the demo code of how to get location by Geolocation.
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API
Hope it helps.
Best Regards
Leo
Find Google Map API, using Webapi the retieve the location data and then populate in the crm.
Hi
try these solution in your plugin
stackoverflow.com/.../get-current-location-using-c-sharp
www.codeproject.com/.../Get-my-laptop-location-using-csharp
csharphelper.com/.../use-the-location-api-to-find-the-computers-latitude-and-longitude-in-c
developerpublish.com/how-to-get-the-current-geo-coordinates-in-windows-phone-using-c
for JavaScript
www.w3schools.com/.../html5_geolocation.asp
developer.mozilla.org/.../Geolocation_API
developer.mozilla.org/.../getCurrentPosition
hope this will help/
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156