Created
March 31, 2016 19:51
-
-
Save adamrobbie/2eb3531d24fa783b2535540f13087803 to your computer and use it in GitHub Desktop.
Revisions
-
adamrobbie created this gist
Mar 31, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ defmodule Havershine do def distance(lng1, lat1, lng2, lat2) do [rLng1, rLat1, rLng2, rLat2] = for deg <- [lng1, lat1, lng2, lat2], do: deg2rad(deg) dLon = rLng2 - rLng1 dLat = rLat2 - rLat1 a = :math.pow(:math.sin(dLat/2), 2) + :math.cos(rLat1) * :math.cos(rLat2) * :math.pow(:math.sin(dLon/2), 2) c = 2 * :math.asin(:math.sqrt(a)) km = 6372.8 * c end defp deg2rad(deg), do: :math.pi()*deg/180 end