Android 在固定位置找到方位

标签 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?

最佳答案

如果 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/

相关文章:

android - 即使有 Activity 客户端也会调用 Service.onUnbind() 吗?

android - Toast 定位不起作用

android - 保护 Android 上的 Twitter key

android - 为 Android ListView 中的行分配 ID

android - 为石斑鱼构建 cyanogenmod 不会创建 CM-*.zip

android - 是否可以从 http header 识别 Android 应用程序?

android - CameraSource .setAutoFocusEnabled(true) 返回 : Camera auto focus is not supported on this device although device supports auto focus

android - 是否可以跳转 Dialogflow 后续 Intent ?

android如何为手机设置虚假位置

Android 在元素下方包含布局