Skip to content

Instantly share code, notes, and snippets.

@voxxit
Created September 4, 2009 04:45
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 voxxit/180734 to your computer and use it in GitHub Desktop.
Save voxxit/180734 to your computer and use it in GitHub Desktop.
/*
* calculate (initial) bearing between two points
* see http://williams.best.vwh.net/avform.htm#Crs
*/
LatLon.bearing = function(lat1, lon1, lat2, lon2) {
lat1 = lat1.toRad(); lat2 = lat2.toRad();
var dLon = (lon2-lon1).toRad();
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
return Math.atan2(y, x).toBrng();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment