0

在我的应用程序中,我想从北方计算特定位置的角度(给出纬度和经度)。有没有办法计算这个。实际上我已经找到了手机的方向,但我想获得位置的角度来自北方。这是我的代码。请提出任何相关的解决方案。谢谢

   myAzimuth=Math.round(event.values[0]);
            myPitch=Math.round(event.values[1]);
            myRoll=Math.round(event.values[2]);
         Toast.makeText(this, "Value"+myAzimuth, Toast.LENGTH_SHORT).show();        
        if(myAzimuth<22){
        Toast.makeText(this, "North Direction", Toast.LENGTH_SHORT).show();     
        }

          else if (myAzimuth >= 22 && myAzimuth < 67)
              Toast.makeText(this, "North East", Toast.LENGTH_SHORT).show();        
          else if (myAzimuth >= 67 && myAzimuth < 112)
              Toast.makeText(this, "East Direction", Toast.LENGTH_SHORT).show();        
          else if (myAzimuth >= 112 && myAzimuth < 157)
              Toast.makeText(this, "South east Direction", Toast.LENGTH_SHORT).show();      
          else if (myAzimuth >= 157 && myAzimuth < 202)
              Toast.makeText(this, "South Direction", Toast.LENGTH_SHORT).show();       
          else if (myAzimuth >= 202 && myAzimuth < 247)
              Toast.makeText(this, "South west Direction", Toast.LENGTH_SHORT).show();      
          else if (myAzimuth >= 247 && myAzimuth < 292)
              Toast.makeText(this, "west Direction", Toast.LENGTH_SHORT).show();        
          else if (myAzimuth >= 292 && myAzimuth < 337)
              Toast.makeText(this, "North west Direction", Toast.LENGTH_SHORT).show();      
          else if (myAzimuth >= 337)
              Toast.makeText(this, "North Direction", Toast.LENGTH_SHORT).show();       
4

1 回答 1

1

根据您所说的“从北方的位置角度”的含义,有几种可能的解决方案。一个是这样的:

final float[] results= new float[3];
// The computed distance in meters is stored in results[0].
// If results has length 2 or greater, the initial bearing is stored in results[1].
// If results has length 3 or greater, the final bearing is stored in results[2].
Location.distanceBetween(refLat, refLong, 90.0f, 0.0f, results);
final float bearing = results[1];

您可以获得从参考位置到北极的路线的方位。方位角/航向在按照最短距离路线行驶时发生变化。

或者按照 Konstantin Pribluda 的建议甚至更好(见下面的评论)

final float bearing = 0.0f;
于 2012-01-19T08:38:49.973 回答