Showing results for 
Search instead for 
Did you mean: 
Regular Visitor

Using getDistanceTo function in Canvas App

I am trying to use a PCF control in one of my canvas app where I am displaying Azure maps using a dataset template. Before showing the data push pins using latitude and longitude, I am trying to get the distance of each push pins from a default location and see whether the distance is within a particular radius or not, and then decides whether to display the pushpin or not. For this purpose, I am using the below code. This line of code throws below exception inside the canvas app but at the same time works fine in the test harness. I have cross-checked all the objects here and nothing is null. I have also checked the passing unit as a parameter thinking that could be a possible issue but with that parameter also the result is the same. Any suggestions or support regarding the same would be really appreciated.


let distanceFromCurrentLocation = atlas.math.getDistanceTo(



Regular Visitor

Experts... any support or suggestions would be really appreciated. Thanks in advance.

Super User
Super User

Hi @renjithpradeep ,

I have never used Azure maps, but the distance between two points can be calculated (in klm) with

      wLat1: YourFirstLatitude,
      wLat2: YourSecondLatitude,
      wLong1: YourFirstLongitude,
      wLong2: YourSecondLongitude,
      wCalc: 0.0174532925199432
   12742 * 
   Asin(Sqrt(0.5 - Cos((wLat1 - wLat2) * wCalc)/2 + 
   Cos(wLat1 * wCalc) * Cos(wLat2 * wCalc) * (1 - Cos((wLong1 - wLong2) * wCalc)) / 2))


Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (4,252)