Android的找到轴承上的固定位置 [英] Android find bearing on a fixed location

查看:195
本文介绍了Android的找到轴承上的固定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新到Android,并通过它学习。所以我想创建一个像指针箭头以显示其中的固定位置是固定的,因为用户将他们的设备时,箭头应自动更新(如指南针)。

我用Google搜索资源,但我不能设法找到它。任何人都知道这里怎么办呢?任何实例或教程会更AP preciated。

例如:

 固定的位置:20纬度,经度50
我的位置:5北纬25,东经
那么,如何找到箭头指向固定的位置?


解决方案

如果curLat和curLon是当前位置的经度和纬度,如果refLat和refLon是参考位置的经度和纬度,你可能会从当前位置到轴承参考位置是这样的:

 最终浮动[] =结果新的浮动[3];
//在米所计算的距离被存储在结果中[0]。
//如果结果具有长度为2或更大,初始轴承被存储在结果中[1]。
//如果结果具有长度3或更大,最终的轴承被存储在结果中[2]。
Location.distanceBetween(curLat,curLon,refLat,refLong,结果);
最终浮动轴承=结果[1];

如果距离增大的结果[2]不同,越来越多的结果[1],除非从当前位置到参考位置的过程中遵循恒向线(或恒向线,在这里看到:的 http://en.wikipedia.org/wiki/Rhumb_line )。

I am very new to Android and learning through it. So i want to create a arrow like pointer to show where is the fixed location is fixed, as the users move their device, the arrow should automatically updated(like compass).

I have googled for resources but i couldn't manage to find it. Anyone here knows how to do it? any examples or tutorials would be much appreciated.

Example:

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

解决方案

If curLat and curLon are the current location's latitude and longitude and if refLat and refLon are the reference location latitude and longitude you may get the bearing from the current location to the reference location like this:

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

If the distance grows result[2] differ more and more from results[1] unless the the course from the current location to the reference location follows a rhumb line (or loxodrome, see here: http://en.wikipedia.org/wiki/Rhumb_line).

这篇关于Android的找到轴承上的固定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆