Reputation:
I have a OpenLayers-3 map with two points. I want to rotate map in direction from p1 to p2 ( like navigation system, when you turn map rotates too).
In android there is function p1.bearingTo(p2) which return bearing in degrees. But it works as expected only when changing longitude, for latitude it is reverse as expected. How to fix that?
Upvotes: 0
Views: 1746
Reputation: 33
In JS, this code calculate the rotation in degrees between 2 points :
var degrees = Math.atan2((nextCoordinate[0] - currentCoordinate[0]), (nextCoordinate[1] - currentCoordinate[1])) * 180 / Math.PI;
if (degrees < 0.0)
degrees += 360.0;
For Android (Java), you could use the same Math atan2 function as described here : http://developer.android.com/reference/java/lang/Math.html#atan2(double, double)
Upvotes: 1