【发布时间】:2013-04-01 14:08:10
【问题描述】:
我已经计算出两个纬度和经度坐标之间的角度,如下代码所示。它返回角度为 3 的弧度和 193 的度数。我想根据这个角度在地图上显示箭头标记。如何根据这个角度显示移动的对象方向?
public static double getAngle(double lat1, double lon1, double lat2, double lon2)
{
//Formulas
//θ = atan2( sin(Δlong).cos(lat2),cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong) )
// Δlong = long2 - long1
Log.i("angle", "Inside getAngle");
double latitude1 = Math.toRadians(lat1);
double longitude1 = Math.toRadians(lon1);
double latitude2 = Math.toRadians(lat2);
double longitude2 = Math.toRadians(lon2);
double dlong = Math.toRadians(longitude2-longitude1);
double y = Math.sin(dlong) * Math.cos(latitude2);
double x = Math.cos(latitude1)*Math.sin(latitude2) - Math.sin(latitude1)*Math.cos(latitude2)*Math.cos(dlong);
double angle= Math.atan2(y, x);
if (angle < 0)
angle = Math.abs(angle);
else
angle = 2*Math.PI - angle;
Log.i("angle", String.valueOf(angle)+" in radians");
angle=Math.toDegrees(angle);
Log.i("angle", String.valueOf(angle)+" in degrees");
return angle;
}
【问题讨论】:
-
所以尝试这样 Uri.parse("maps.google.com/maps?f=d&daddr=51.448,-0.972")); 得到两点之间的方向..
-
不,我不想使用 Google Directions API 和路线。我已经有了路线位置。只是我想用带箭头的折线连接。
标签: android google-maps geometry compass-geolocation