我有一個應用程序,我想要做一些自定義指南針功能假設我有位置A和位置B我標記我的位置(位置A),然後我移動一些距離我的指南針應指向定位問題的地方,我可以移動我正在引用qiblacompass的功能,但它不是指向位置,當我移動到這裏其他位置是我的代碼如何獲取角度使用兩個經度和緯度
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是我的位置的緯度,經度和degLitudeitude是那些當我移動它從我的GPS獲取lat,lng
任何人請告訴我wha t在這段代碼中是錯誤的還是我用其他方法來完成我的任務?
這可以幫助你https://software.intel.com/zh-cn/blogs/2012/11/30/calculating-a-bearing-between-points位置感知應用程序 – 2014-12-02 10:51:04
如果您希望您的指南針指向位置A,那麼位置B與此有何關係? – greenapps 2014-12-02 10:51:16
locationB是當我移動然後它得到經緯度 – hena12 2014-12-02 11:09:43