Skip to content

Instantly share code, notes, and snippets.

@edymerchk
Created September 11, 2014 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edymerchk/029e3f5e6fac2ab56edc to your computer and use it in GitHub Desktop.
Save edymerchk/029e3f5e6fac2ab56edc 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