web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Getting error while accessing the Microsoft.Maps.Location in JavaScript

(0) ShareShare
ReportReport
Posted on by

Hi,

I am looking into to get the distance between locations (using Bing Map) in Javascript but getting the error "Cannot read property 'Location' of undefined" error.

The Microsoft.Maps.Location method causing issue. Can anyone help how to fix this issue?

 

Below is my JavaScript code:  

function distanceCalculation(executionContext) {
var formContext = executionContext.getFormContext();

var hLatitude = "17.38405";
var hLongitude = "78.45636";

var bLatitude = "12.971599";
var bLongitude = "77.594566";

getDistanceBetweenLocations(new Microsoft.Maps.Location(hLatitude, hLongitude), new Microsoft.Maps.Location(bLatitude, bLongitude));

}


// Calculate distance between two locations.
function getDistanceBetweenLocations(Location1, Location2) {
Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath', function () {
var vDistance = Microsoft.Maps.SpatialMath.getDistanceTo(Location1, Location2, Microsoft.Maps.SpatialMath.DistanceUnits.Miles);
alert("Distance in Miles : " + vDistance);
});
}

Thanks,

Naveen

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    As far as I understood you want to use Bing Maps Services for calculation of the distance. Did you include the corresponding modules in order to use them in your code? I assume you have not.

  • Community Member Profile Picture
    on at

    Hi Andrew,

    Thanks for your reply.

    Yes, I am trying to use the Bing Map API to achieve this functionality.

    Actually I am referring to the below sample JS code to achieve this. As per my requirement I am implementing this functionality In JS not in HTML.

    mscrmtechie.blogspot.com/.../distance-between-two-locations-bing-maps.html

    I am not sure how I can reference the the below Bing Map API in JS library (Field Onchange event), so that I am getting this error.

    Could you please help how I can refer this API URL in JS library?

    src='www.bing.com/.../mapcontrol async defer

    Thanks,

    Naveen

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Naveen,

    You will have to load that file "on the fly". Here are few possible ways - stackoverflow.com/.../ways-to-add-javascript-files-dynamically-in-a-page

  • Community Member Profile Picture
    on at

    Hi Andrew,

    Ok, let me try this.

    Thanks,

    Naveen

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans