Showing results for 
Search instead for 
Did you mean: 
New Member

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(



New Member

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

PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.


Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,239)