Closed objectiveSee closed 9 years ago
FYI: I understand trig, but didn't put any thought into this one (I googled it). Perhaps the solution is incorrect for a curved surface like Earth.
Can you send a pull request? I will have a look then ;)
Thank you!
I am sure that this bearing function is incorrect, because it does not take into account the size of the Earth.
What about this ...
function radians(n) {
return n * (Math.PI / 180);
}
function degrees(n) {
return n * (180 / Math.PI);
}
function getBearing(startLat,startLong,endLat,endLong){
startLat = radians(startLat);
startLong = radians(startLong);
endLat = radians(endLat);
endLong = radians(endLong);
var dLong = endLong - startLong;
var dPhi = Math.log(Math.tan(endLat/2.0+Math.PI/4.0)/Math.tan(startLat/2.0+Math.PI/4.0));
if (Math.abs(dLong) > Math.PI){
if (dLong > 0.0)
dLong = -(2.0 * Math.PI - dLong);
else
dLong = (2.0 * Math.PI + dLong);
}
return (degrees(Math.atan2(dLong, dPhi)) + 360.0) % 360.0;
}
oups, method exists in source but no documentation in readme ...
https://github.com/manuelbieh/Geolib/blob/master/src/geolib.js#L749
I implemented a method to calculate bearing between points which could be useful. Should we add this?
// From http://www.movable-type.co.uk/scripts/latlong.html var bearingFromPoints = function (pointA, pointB) { var lat1 = pointA.latitude; var lon1 = pointA.longitude; var lat2 = pointB.latitude; var lon2 = pointB.longitude;
};