安卓指南针
我目前正在开发一个应用程序,它可以获取用户的位置并确定最近的公交车站,然后在屏幕上显示从该站出发的出发时间。现在我想制作一个指向那个公交车站的指南针,但我不太确定如何实现这一点。任何指导方针将不胜感激。
I am currently developing an application that takes the users position and determine which bus stop is closest and then show the departures from that stop on the screen. Now I want to make a compass which points towards that bus stop and I'm not quite sure how to achieve this. Any guidelines would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 API 的示例中,有一个实现了简单的指南针。它由以下类组成:CompassActivity、GraphicsActivity 和 PictureLayout。它显示了一根指向磁北的简单指针。
您可以使用 GeoMagneticField.get Declination() 获得与真北的变化,从而进行调整以使针指向真北。
假设您知道 1):您的位置(例如 myLocation),2):公交车站的位置(例如 stopLocation)。您可以使用 myLocation.bearingTo(stopLocation) 为您提供前往巴士站的方位。然后,您需要做的就是将此轴承添加到补偿罗盘轴承中,以使指针指向公交车站。 (磁北方位位于 SensorEventListener 中的 event.values[0] 中)
In the examples for the API, there is one which implements a simple compass. It's comprised of the following classes: CompassActivity, GraphicsActivity and PictureLayout. Is shows a simple needle pointing to magnetic North.
You can use GeomagneticField.get Declination() to give you the variation from true North and thus adjust to make the needle point true North.
Assuming you know 1): your location (myLocation, say), 2): the bus stop's location (stopLocation, say). You can use myLocation.bearingTo(stopLocation) to give you the bearing to the bus stop. All you need do then is to add this bearing to the compensated compass bearing to make the needle point to the bus stop. (The bearing to magnetic North is in event.values[0] in the SensorEventListener)
这是一个老问题,但也许这会对某人有所帮助:
我开发了一个小助手类: 指南针助手
此类提供手机相对于北方的航向。它具有获取两个位置之间的方位角的功能。如果您将手机的当前位置作为第一个位置,则可以获得方位并将其显示给用户。
请随时向我询问或向我提供有关助理的反馈。
this is an old question but maybe this will help someone:
I developed a small Helper Class: Compass Assistant
This class provides the heading of the phone relative to north. It has a function to get the bearing between two locations. If you pass the phone´s current location as the first location, you can get the bearing and show it to the user.
Don´t hesitate to ask me or give me feedback for the assistant.