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).