Skip to content

Instantly share code, notes, and snippets.

@Thorium
Created April 13, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thorium/eef69eb53cb6cb7746d985119228a787 to your computer and use it in GitHub Desktop.
Save Thorium/eef69eb53cb6cb7746d985119228a787 to your computer and use it in GitHub Desktop.
Calculate distance between two GPS latitude-longitude points.
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