我有一个带有两个点的OpenLayers-3地图。我想旋转地图的方向从p1到p2 (就像导航系统,当你打开地图旋转也)。
在android中,有一个函数p1.bearingTo(p2),它以度为单位返回方位角。但它只有在更改经度时才能按预期工作,对于纬度,它的工作方式与预期相反。如何解决这个问题?
发布于 2015-04-12 16:33:08
在JS中,此代码计算两点之间的旋转度数:
var degrees = Math.atan2((nextCoordinate[0] - currentCoordinate[0]), (nextCoordinate[1] - currentCoordinate[1])) * 180 / Math.PI;
if (degrees < 0.0)
degrees += 360.0;对于安卓(Java),您可以使用与这里描述的相同的数学atan2函数:http://developer.android.com/reference/java/lang/Math.html#atan2(double
发布于 2015-03-25 22:04:15
bearing = 180 - p1.bearingTo(p2)这将切换y asis。
https://stackoverflow.com/questions/29255939
复制相似问题