Can someone help me fill in the blanks with native JavaScript?
function getHeading(lat1, lon1, lat2, lon2) {
// Do cool things with math here
return heading; // Should be a number between 0 and 360
}
I've been messing around with this for a long time and can't seem to get my code to work right.
There is a very good JavaScript implementation by Chris Veness at Calculate distance, bearing and more between Latitude/Longitude points under the Bearings heading.
You may prefer augmenting Google's
LatLng
prototype with agetHeading
method, as follows (using the v3 API):Which then can be used like this:
Otherwise if you prefer a global function instead of augmenting Google's
LatLng
, you can do it as follows:Usage: