How to Calculate Distance Between Lat/Long Data for Your Dashboards (Video Tip)

If you are collecting geographical data, there are many operations you might wish to perform to enhance your ability to report on this data. One of these might be calculating the distance between two latitude/longitude points to know their distance apart. Generally, it would be helpful to know things like the distance to your customers or even help understand shipping costs - there are many reasons you might want this information! In this video, I will show you how to calculate the space between two points for high-level reporting.

var lat1 = $Lat$;
var lon1 = $Long$;

var lat2 = 43.6532;
var lon2 = -79.3832;

double rlat1 = Math.PI*lat1/180;
double rlat2 = Math.PI*lat2/180;
double theta = lon1 - lon2;
double rtheta = Math.PI*theta/180;
double dist =
  Math.Sin(rlat1)*Math.Sin(rlat2) + Math.Cos(rlat1)*
  Math.Cos(rlat2)*Math.Cos(rtheta);
dist = Math.Acos(dist);
dist = dist*180/Math.PI;
dist = dist*60*1.1515;
return dist;

If you’d like to learn more, I’d recommend you go to my learning channel - Off the Charts (with Jeff).
https://www.dundas.com/resources/off-the-charts-tips-from-an-expert

1 Like

Hi Jeff,

You forgot to multiply by 1.609344 to have the result in kilometers, which is the international distance measurement unit :wink:
An observation satellite crashed a few years ago because of people using miles instead of kilometers in an international project, therefore transmitting wrong measures for the distance of security to be respected in order for the satellite to escape the attraction of the planet to be observed. :innocent:

I’m pretty sure they also crashed a probe (or two) into Mars for similar reasons! Thanks for the post @romero.olivier

1 Like

They did indeed crash a probe on to Mars because of that. (Although they may have changed their mind if that was the reason).
The probe was called Beagle and the flight director was devastated that he couldn’t announce that ‘The Beagle has landed’.

That’s heartbreaking!!! The Beagle has landed is awesome. Thanks for sharing the story.