根据用户方向计算两个位置之间的轴承角度

时间:2012-09-04 07:30:22

标签: android

我使用以下方法查找当前位置和目的地位置之间的角度。

public  float calculateBearing(Location before, Location after) {
     Point pBefore = location2Point(before);
         Point pAfter = location2Point(after);
float res = -(float) (Math.atan2(pAfter.y - pBefore.y,pAfter.x-pBefore.x)*180/ Math.PI) + 90.0f;
          if (res < 0)
      {
          Log.e("angle ",""+(res + 360.0f));
              return res + 360.0f;
      }
      else
      {
          Log.e("angle ",""+res);
              return res;
      }
    }

但是这会给用户当前位置的角度始终朝向北方。但是如果用户转向南方或东方,我还需要根据用户承载来计算角度。

我知道使用传感器管理器可以计算轴承角度。但我如何从用户当前位置计算到目的地位置。

提前致谢

0 个答案:

没有答案
相关问题