正如标题所说,我有当前位置,并且想知道从我当前位置到其他位置的度数。我已阅读this post,是我的答案location.getBearing()返回的值吗?android - 我如何获得两个位置之间的方位度?
让我们简单说一下:从图片上我预计45度的价值。
正如标题所说,我有当前位置,并且想知道从我当前位置到其他位置的度数。我已阅读this post,是我的答案location.getBearing()返回的值吗?android - 我如何获得两个位置之间的方位度?
让我们简单说一下:从图片上我预计45度的价值。
我遇到了麻烦,并设法弄清楚转换C?方法来计算方位度。
我工作了这一点,使用4个坐标点
开始纬度
开始经度
末纬度
末经度
下面的代码:
protected double bearing(double startLat, double startLng, double endLat, double endLng){
double longitude1 = startLng;
double longitude2 = endLng;
double latitude1 = Math.toRadians(startLat);
double latitude2 = Math.toRadians(endLat);
double longDiff= Math.toRadians(longitude2-longitude1);
double y= Math.sin(longDiff)*Math.cos(latitude2);
double x=Math.cos(latitude1)*Math.sin(latitude2)-Math.sin(latitude1)*Math.cos(latitude2)*Math.cos(longDiff);
return (Math.toDegrees(Math.atan2(y, x))+360)%360;
}
只需更改需要的变量名称即可。
输出轴承一个TextView
希望它帮助!
位置有方法bearingTo: 浮动bearingTo(DEST位置)
Location from = new Location(LocationManager.GPS_PROVIDER);
Location to = new Location(LocationManager.GPS_PROVIDER);
from.setLatitude(0);
from.setLongitude(0);
to.setLongitude(10);
to.setLatitude(10);
float bearingTo = from.bearingTo(to);
什么是该方法的文档告诉你吗?这个问题是不可能的,因为你没有说过为什么你认为'getBearing()'是**不是正确的方法。 – Simon
使用浮动轴承= myLocation.bearingTo(otherLocation); – NickT