如何创建一个指针始终指向某个 GPS 位置的指南针? (在安卓系统中)
我想在 Android 中编写一个应用程序,您可以在其中看到一个始终指向某个 GPS 位置的指针。因此,当您转动手机或驾车行驶时,指针仍会指向 GPS 位置。
但我不知道如何使用 GPS 位置和指南针传感器数据进行计算。
任何人都可以给我一些如何开始的指示,或者可以举一个如何执行此操作的示例吗?
I would like to write a app in Android where you see a pointer that always point to a certain GPS position. So when you are turning your phone or driving around the pointer will still point to the gps position.
But I have no idea how to do the calculations with the gps position and the compass sensordata.
Can anyone give me some pointers how to get started or maybe have a example of how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了实现这一点,您需要了解几件事:
使用 android LocationManager 并注册位置更新。当这些更新到达时,您需要提取位置和方位(也可以使用指南针作为方位)并将其转换为您正在使用的地图格式。通常这将是谷歌地图球形墨卡托变体。
有了这些信息,您可以使用三角学来计算您和标记位置之间的角度,并使用它在地图上绘制方向箭头,或者使用方位数据告诉您转向哪个方向。
To achieve this you will need to know several things:
Use the android LocationManager and register for position updates. When these updates arrive you need to extract the position and bearing (could also use compass for bearing) and convert them to the map format you are using. Commonly this will be the Google maps spherical Mercator variation.
With this information you can use trigonometry to calculate the angle between you and your tagged location and use this to draw your direction arrow on a map, or with the bearing data to tell you which way to turn.
与上述答案相同的起点,但不需要三角计算。只需调用现有方法。
您
的实际位置。您现在可以
或者,如果您想要更短的线(或箭头),
Same starting point as above answer, but no trigonometry calculation required. Just calls of existing methods.
You have
You can now
or if you want a shorter line (or arrow)