我是 Android 的新手,正在通过它学习。所以我想创建一个像指针一样的箭头来显示固定位置是固定的,当用户移动他们的设备时,箭头应该自动更新(就像指南针)。
我用谷歌搜索了资源,但找不到。这里有人知道怎么做吗?任何示例或教程将不胜感激。
例子:
fixed location: 20 latitude, 50 longitude
my location: 5 latitude 25, longitude
So how do i find the arrow pointed to fixed location?
最佳答案
如果 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];
如果距离增加 result[2] 与 results[1] 的差异越来越大,除非从当前位置到引用位置的路线遵循恒向线(或 loxodrome,参见此处:http://en.wikipedia.org/wiki/Rhumb_line)。
关于Android 在固定位置找到方位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9044283/