Android 指南针在不同手机上读取不同的值?

发布于 2024-09-17 05:07:16 字数 252 浏览 7 评论 0原文

你好:)我正在开发一个应用程序,它使用指南针和位置在某个位置的方向上绘制箭头。我的问题是,当我在模拟器上运行代码时,所有箭头都指向正确的方向,并且当我将模拟器的方向更改为横向时,所有箭头仍然正确。但是,当我在 Nexus One 上运行相同的应用程序时,当手机垂直时,箭头都是正确的,但当手机横向时,所有箭头都会偏离 90 度。它保留手机的“顶部”作为对北的参考。因此,您必须根据手机的方向校正指南针。是否所有真机都会出现这种情况,而模拟器则不同?或者这只是 Nexus One?谢谢 :)

Hello :) I am working on an application that uses the compass and location to draw an arrow at the direction of a location. My problem is when I run my code on the emulator, all the arrows point the correct directions, and when I change the orientation of the emulator to landscape, all the arrows are still correct. But when I run the same application on my Nexus One, the arrows are all correct when the phone is vertical, but when it turns to landscape all of the arrow are off by 90 degrees. It keeps the "top" of the phone as the reference to North. Thus you must correct the compass for the orientation of the phone. Does this happen on all real phones and the emulator is the different one? Or is this just the Nexus One? Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦上情书 2024-09-24 05:07:16

根据我的理解,指南针当前的工作方式应该始终使用手机的“顶部”或“默认方向”来正确读取。这在早期版本的 Android 上可能有所不同。据说,开发人员需要通过方向变化来补偿屏幕方向以代表真正的北方。对于加速度计来说也是如此,轴保持基于默认屏幕方向(因此对于大多数手机来说是纵向的,但平板电脑大多数是横向的)。
我不想向您推荐 sdk,但此链接第一段解释了:
http://developer.android.com/reference/android/hardware/SensorEvent.html

From my understanding the current way the compass works it is supposed to always use the "top" of the phone or "default orientation" for the correct reading. This could have been different on earlier versions of android. It is said it is then up to developers to compensate for the screen orientation to represent the true north with orientation changes. Same goes for the accelerometer the axis stay based off of default screen orientation (so for most phones portrait, but tablets most would be landscape).
I hate to refer you to the sdk but this link first paragraph explains:
http://developer.android.com/reference/android/hardware/SensorEvent.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文