Created
December 3, 2025 21:58
-
-
Save cbaragao/3e47163d45e98792037a69010c038298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Function to calculate the distance between two geographic coordinates | |
| GetDistance(lat1:Number, lon1:Number, lat2:Number, lon2:Number):Number = With( | |
| { | |
| // Convert latitude and longitude differences from degrees to radians | |
| dLat: (lat2 - lat1) * Pi() / 180.0, | |
| dLon: (lon2 - lon1) * Pi() / 180.0, | |
| // Convert original latitudes to radians | |
| rLat1: lat1 * Pi() / 180.0, | |
| rLat2: lat2 * Pi() / 180.0 | |
| }, | |
| With( | |
| { | |
| // Apply the Haversine formula | |
| a: (Power( | |
| Sin(dLat / 2), | |
| 2 | |
| ) + Power( | |
| Sin(dLon / 2), | |
| 2 | |
| ) * Cos(rLat1) * Cos(rLat2)), | |
| // Earth's radius in kilometers | |
| rad: 6371, | |
| convert_to_miles: 0.621371 | |
| }, | |
| // Final distance calculation using the inverse haversine and convert to miles | |
| (rad * (2 * Asin(Sqrt(a)))) * convert_to_miles | |
| ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment