2012-01-28 81 views
3

我對Android非常陌生,並且通過它進行學習。所以我想創建一個像指針一樣的箭頭來顯示固定位置在哪裏固定,當用戶移動他們的設備時,箭頭應該自動更新(如指南針)。Android在固定位置找到方位

我已經搜索了資源,但我無法找到它。這裏的任何人都知道如何去做?任何示例或教程將不勝感激。

例子:

fixed location: 20 latitude, 50 longitude 
my location: 5 latitude 25, longitude 
So how do i find the arrow pointed to fixed location? 

回答

6

如果curLat和curLon是當前位置的緯度和經度,如果refLat和refLon是參考位置的經度和緯度,你可能會從當前位置的軸承,如參考位置此:

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(curLat, curLon, refLat, refLong, results); 
final float bearing = results[1]; 

如果距離增大導致[2]不同於結果越來越[1]除非從當前位置到參考位置的過程如下一個恆向線(或恆向線,在這裏看到:http://en.wikipedia.org/wiki/Rhumb_line)。