Skip to content

Instantly share code, notes, and snippets.

@sabas
Created November 2, 2014 11:35
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 sabas/967219ce4453c01de4bf to your computer and use it in GitHub Desktop.
Save sabas/967219ce4453c01de4bf to your computer and use it in GitHub Desktop.
Just an implementation of haversine formula in JS
function haversine(lat1,lon1,lat2,lon2)
{
var R = 6372797.560856;
var dlat = (lat2-lat1).toRad();
var dlon = (lon2-lon1).toRad();
var lonh=Math.sin(dlon*0.5);
lonh*=lonh;
var lath=Math.sin(dlat*0.5);
lath*=lath;
var tmp= Math.cos(lat1.toRad())*Math.cos(lat2.toRad());
return 2*R*Math.asin(Math.sqrt(lath+tmp*lonh));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment