0

私のアプリでは、北から特定の場所(緯度と経度が示されています)の角度を計算したいです。これを計算する方法はありますか?実際には、電話の方向を入力しましたが、位置の角度を取得したい北から。ここに私のコードがあります。関連する解決策を提案してください。Thankx

   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

「北からの位置の角度」の意味に応じて、いくつかの可能な解決策があります。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 に答える