Skip to content

Instantly share code, notes, and snippets.

@jvehent
Created February 6, 2018 15:50
Show Gist options
  • Save jvehent/74ef9b3c87be5ec100e766b38f854638 to your computer and use it in GitHub Desktop.
Save jvehent/74ef9b3c87be5ec100e766b38f854638 to your computer and use it in GitHub Desktop.
require “math”
function haversine(lat1, lon1, lat2, lon2)
lat1 = lat1 * math.pi / 180
lon1 = lon1 * math.pi / 180
lat2 = lat2 * math.pi / 180
lon2 = lon2 * math.pi / 180
lat_dist = lat2-lat1
lon_dist = lon2-lon1
lat_hsin = math.pow(math.sin(lat_dist/2),2)
lon_hsin = math.pow(math.sin(lon_dist/2),2)
a = lat_hsin + math.cos(lat1) * math.cos(lat2) * lon_hsin
return 2* 6372.8 * math.asin(math.sqrt(a))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment