2012-01-19 101 views
0

在我的應用程序中,我想從north.is計算具體位置(經緯度和長度都給出)的角度。有沒有什麼辦法來計算這個。實際上,我發現把手機的方向,但我想獲得角度從north.here位置是我的code.please提出任何有關solution.Thankx如何從android中獲取任何地理位置的角度?

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();  
+0

[相關問題](http://stackoverflow.com/questions/4308262/calculate-compass-bearing-heading-to-在Android中的位置) – st0le

+0

你知道經度和緯度是從赤道和格林威治經度測量的嗎?北極緯度北緯90度,經度0度。你剛剛計算出手機用戶在哪個方向旅行? – ChrisBD

+0

如果myAzimuth位於(0-21),那麼方向是什麼? – Khawar

回答

0

根據你的意思是「來自北方的位置的角度」什麼有幾種可能的解決方案。一個是這樣的:

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]; 

您可以獲得從參考位置到北極的路線的方位。在最短路程上沿着路線改變方位/方位。

甚至更​​好的康斯坦丁Pribluda的建議(見下文評論)

final float bearing = 0.0f; 
+0

從每個位置到北極的方位都是0;)它不會改變。 –

+0

當然,你說得對,北極最短路徑是與每90度經度的經線相交的垂線(或loxodrome)。所以代碼很容易重構爲 final bearing = 0.0f; // :-) 但是,您可以選擇任何初始軸承,但不包括-90和90度,並最終通過遵循恆定線來達到北極...... ;-) – Stefan

相關問題