bearingTo(Location dest)准确计算什么?谁能解释一下吗?

提前致谢。

 protected void onCreate(Bundle savedInstanceState) {
    DestinationLoc.setLatitude(39.543394);
    DestinationLoc.setLongitude(-119.816010);
    LocationManager lm =(LocationManager)getSystemService(LOCATION_SERVICE);
    String provider = lm.getBestProvider(new Criteria(), true);
    loc=lm.getLastKnownLocation(provider)
    }

    public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub
      Startloc.setLatitude(loc.getLatitude());
      Startloc.setLongitude(loc.getLongitude());
    if ( Startloc == null ) return;

    float azimuth = event.values[0];
    float baseAzimuth = azimuth;
    mInitialPosition.setText("Initial LatLong: " + Startloc.getLatitude() + " " + Startloc.getLongitude());
    GeomagneticField geoField = new GeomagneticField( Double
            .valueOf( Startloc.getLatitude() ).floatValue(), Double
            .valueOf( Startloc.getLongitude() ).floatValue(),
            Double.valueOf( Startloc.getAltitude() ).floatValue(),
            System.currentTimeMillis() );
    azimuth += geoField.getDeclination(); // converts magnetic north into true north

    //Correct the azimuth
    azimuth = azimuth % 360;

    //This is where we choose to point it
    float direction = azimuth + Startloc.bearingTo( DestinationLoc );
    float direction2 = Startloc.bearingTo(DestinationLoc);


}

direction2值显示为负。

最佳答案

请阅读documentation。它准确地描述了该方法返回的结果。


  以真实北向东的度数返回近似初始方位角
  沿着此位置与目的地之间的最短路径行驶时
  给定的位置。使用WGS84定义最短路径
  椭球。 (几乎)对立的位置可能会产生
  没有意义的结果。
  
  参量
  
  目标位置
  
  退货
  
  初始方位角(度)

10-08 14:12