正如标题所说,我有当前位置,并想知道从我当前位置到其他位置的度数。我看过this post,是按location.getBearing()回复的值吗?
简单地说:从图片中,我预计45度的值。
答案 0 :(得分:3)
我在做这件事时遇到了麻烦并设法解决了转换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
希望它有所帮助!
答案 1 :(得分:2)
位置有方法bearingTo: float bearingTo(Location 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);
答案 2 :(得分:1)
以下是计算两点(startPoint,endPoint)之间的方位角的代码:
public float CalculateBearingAngle(double startLatitude,double startLongitude, double endLatitude, double endLongitude){
double Phi1 = Math.toRadians(startLatitude);
double Phi2 = Math.toRadians(endLatitude);
double DeltaLambda = Math.toRadians(endLongitude - startLongitude);
double Theta = atan2((sin(DeltaLambda)*cos(Phi2)) , (cos(Phi1)*sin(Phi2) - sin(Phi1)*cos(Phi2)*cos(DeltaLambda)));
return (float)Math.toDegrees(Theta);
}
征集职能:
float angle = CalculateBearingAngle(startLatitude, startLongitude, endLatitude, endLongitude);