Created
April 13, 2016 15:02
-
-
Save Thorium/eef69eb53cb6cb7746d985119228a787 to your computer and use it in GitHub Desktop.
Calculate distance between two GPS latitude-longitude points.
This file contains 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
open System | |
let ``calculate distance`` (p1Latitude,p1Longitude) (p2Latitude,p2Longitude) = | |
let r = 6371.0; // km | |
let dLat = (p2Latitude - p1Latitude) * Math.PI / 180.0 | |
let dLon = (p2Longitude - p1Longitude) * Math.PI / 180.0 | |
let lat1 = p1Latitude * Math.PI / 180.0 | |
let lat2 = p2Latitude * Math.PI / 180.0 | |
let a = Math.Sin(dLat/2.0) * Math.Sin(dLat/2.0) + | |
Math.Sin(dLon/2.0) * Math.Sin(dLon/2.0) * Math.Cos(lat1) * Math.Cos(lat2) | |
let c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0-a)) | |
r * c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment