Skip to content

Commit

Permalink
Update Spherical.js
Browse files Browse the repository at this point in the history
The current implementation of OpenLayers.Spherical.computeHeading() is wrong based on the relevant [link](http://www.movable-type.co.uk/scripts/latlong.html) listed in Spherical.js. The delta of the longitudes is reversed in both the 'y' and the 'x' portion of the equations. Instead of `from.lon - to.lon`, it should be `to.lon - from.lon`.
  • Loading branch information
mrmattson committed Dec 4, 2014
1 parent 541e65b commit 2eea5c3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/OpenLayers/Spherical.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ OpenLayers.Spherical.computeDistanceBetween = function(from, to, radius) {
* {Float} The heading in degrees.
*/
OpenLayers.Spherical.computeHeading = function(from, to) {
var y = Math.sin(Math.PI * (from.lon - to.lon) / 180) * Math.cos(Math.PI * to.lat / 180);
var y = Math.sin(Math.PI * (to.lon - from.lon) / 180) * Math.cos(Math.PI * to.lat / 180);
var x = Math.cos(Math.PI * from.lat / 180) * Math.sin(Math.PI * to.lat / 180) -
Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (from.lon - to.lon) / 180);
Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (to.lon - from.lon) / 180);
return 180 * Math.atan2(y, x) / Math.PI;
};

0 comments on commit 2eea5c3

Please sign in to comment.