我正在开发一个实现谷歌地图的应用程序。我使用下面的代码计算方位。当我向一个方向移动时,如果我突然改变方向,轴承不会立即移动,这违背了我的目的app.Here是计算轴承的代码
protected static double bearing(double lat1, double lon1, double lat2, double lon2){
double longDiff= Math.toRadians(lon2-lon1);
double y = Math.sin(longDiff)*Math.cos(Math.toRadians(lat2));
double x = Math.cos(Math.toRadians(lat1))*Math.sin(Math.toRadians(lat2))-Math.sin(Math.toRadians(lat1))*Math.cos(Math.toRadians(lat2))*Math.cos(longDiff);
return ( Math.toDegrees(Math.atan2(y, x)) + 360 ) % 360;
}