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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using getDistanceTo fu...
Power Apps
Unanswered

Using getDistanceTo function in Canvas App

(0) ShareShare
ReportReport
Posted on by 2

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 atlas.data.Position(this.defaultLongitude,this.defaultLatitude),
new atlas.data.Position(longitude,latitude))/1000;

 

 

GetDistanceError.jpg
Categories:
  • renjithpradeep Profile Picture
    2 on at

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

  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @renjithpradeep ,

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

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard