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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 196 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 129

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans