Skip to content

Instantly share code, notes, and snippets.

@esbanarango
Forked from edymerchk/distance.coffee
Last active August 29, 2015 14:13
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 esbanarango/31178303561ebbf3b63a to your computer and use it in GitHub Desktop.
Save esbanarango/31178303561ebbf3b63a to your computer and use it in GitHub Desktop.
# based on Haversine formula
# http://en.wikipedia.org/wiki/Haversine_formula
distance = (lat1, lon1, lat2, lon2) ->
R = 6371
a = 0.5 - Math.cos((lat2 - lat1) * Math.PI / 180) / 2 + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * (1 - Math.cos((lon2 - lon1) * Math.PI / 180)) / 2
R * 2 * Math.asin(Math.sqrt(a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment