“旋转”在Expo-Sensers' devicemotion准确地返回?

发布于 2025-02-07 03:56:15 字数 729 浏览 1 评论 0原文

我正在构建一个应用程序,我需要在其中依靠指南针/轴承/朝您称呼的内容:北方和手机的Y轴之间的角度。

我阅读了互联网的大部分,并了解了“传感器融合”,它是Android中rotation_vector的虚拟形式。我熟悉 and

将其归结为Expo-Sensors的DeviceMotion,我的测试代码看起来像是如此:

import { DeviceMotion } from 'expo-sensors'

DeviceMotion.addListener( ({ rotation }) => 
  console.info( ( 360 + this.toDegreesInt( rotation.alpha ) ) % 360 ) 
)

现在,如果我旋转设备,该值以某种方式变化,但是如果我指向北部,我会得到124度的角度,远远超出了该角度未校准的罗盘读数。

另外,如果我旋转设备360度,则假定的方位值永远不会从0到359,而是在某些随机扩散的块中。

在同一设备上的Google导航工作如魅力...

如何使我的指南针起作用?

I'm building an App where I need to rely on compass azimuth/bearing/heading whatever you call it: the angle between the North and the Y-axis of the phone.

I read the greater half of the Internet and learned about "Sensor fusion" and it's virtual form of ROTATION_VECTOR in Android. I got familiarized with SensorManager and DeviceMotionModule.

Boiling it down to expo-sensors' DeviceMotion, my test code looks like so:

import { DeviceMotion } from 'expo-sensors'

DeviceMotion.addListener( ({ rotation }) => 
  console.info( ( 360 + this.toDegreesInt( rotation.alpha ) ) % 360 ) 
)

Now if I rotate the device, the value changes somehow, but if I point it to the North, I get an angle of 124 degrees which is far beyond the uncalibrated compass reading.

Also, if I rotate the device 360 degrees, the supposed azimuth value never goes from 0 to 359, but rather in some randomly spread chunks.

Google Navigation on the very same device works like charm...

How can I make my compass work?

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

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

发布评论

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

评论(1

孤星 2025-02-14 03:56:15

我最终使用了Expo-Location模块喜欢:

import * as Location from 'expo-location'

Location.watchPositionAsync( {..}, ({ coords }) => console.info( coords.latitude, coords.longitude ) )

coords对象具有带有有效度量的最终数据,并且不需要其他处理。

I ended up using the expo-location module like so:

import * as Location from 'expo-location'

Location.watchPositionAsync( {..}, ({ coords }) => console.info( coords.latitude, coords.longitude ) )

The coords object has final data with valid measures, and no additional processing is required.

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