【发布时间】:2014-12-02 10:42:40
【问题描述】:
我有一个应用程序,我想在其中执行一些自定义指南针功能假设我有位置 A 和位置 B 我标记了我的位置(位置 A)然后我移动了一段距离我的指南针应该指向位置 A 我可以移动的任何地方我正在引用 qiblacompass 功能,但当我移动到其他位置时它没有指向位置 A 这是我的代码
public static double getDirectionFromNorth(double degLatitude,
double degLongitude) {
final double direction_LATITUDE = Math.toRadians(angle_lat);
double direction_LONGITUDE = Math.toRadians(angle_lng);
double latitude2 = Math.toRadians(degLatitude);
double longitude = Math.toRadians(degLongitude);
double soorat = Math.sin(direction_LONGITUDE - longitude);
double makhraj = Math.cos(latitude2) * Math.tan(direction_LATITUDE)
- Math.sin(latitude2) * Math.cos(direction_LONGITUDE - longitude);
double returnValue = Math.toDegrees(Math.atan(soorat / makhraj));
if (latitude2 > direction_LATITUDE) {
if ((longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > 0 && returnValue <= 90)) {
returnValue += 180;
} else if (!(longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > -90 && returnValue < 0)) {
returnValue += 180;
}
}
if (latitude2 < direction_LATITUDE) {
if ((longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > 0 && returnValue < 90)) {
returnValue += 180;
}
if (!(longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > -90 && returnValue <= 0)) {
returnValue += 180;
}
}
// ***
return returnValue;
}
其中 angle_lat 和 angle_lng 是我的位置 纬度、经度和 degLatitude、degLongitude 是当我移动它时从我的 GPS 获取 lat、lng 的位置
请告诉我这段代码有什么问题,或者我有什么其他方法可以完成我的任务吗?
【问题讨论】:
-
如果您希望您的指南针指向 locationA,那么 locationB 与这一切有什么关系?
-
locationB 是当我移动时,它会变长
-
所以locationB就是罗盘的位置!?
-
指南针应该指向LocationA
标签: android google-maps gps compass-geolocation google-geolocation