如何获取高质量的指南针方向(如在Google地图中)? [英] How to retrieve high quality compass orientation (as in Google Maps)?

查看:324
本文介绍了如何获取高质量的指南针方向(如在Google地图中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现所有在Android中获取指南针方向的指南都有一个错误:当您以纵向模式握住手机并在地平线上方看"时,指南针箭头会从正确的方向旋转180度.

All of the guides to getting compass orientation in Android I've found have a bug: when you hold the phone in portrait mode and "look" above the horizon, the compass arrow turns 180 degrees from the correct direction.

Google Maps方向指示器没有此问题.

Google Maps orientation indicator doesn't have this problem.

Google Maps的另一个好处是,它们以某种方式估计了指南针的准确性.知道他们是怎么做到的吗?

Another nice thing that Google Maps have is that they somehow estimate compass accuracy. Any idea how they do this?

推荐答案

您询问的错误是由于欧拉角或称为万向节锁引起的.

Error you ask is caused because of Euler angles or called Gimbal Lock.

要解决很大的角度差,应在使用重力传感器获得倾斜度或从具有低通滤波器的加速度计获得重力后,检查设备是否平坦或没有检查倾斜度.如果它不是平坦的(AR应用程序或倾斜度> 25 ||倾斜度<155),则将坐标系从x,y重映射到x,z.这样可以解决问题.

To solve very high angle difference, you should check if your device is flat or not checking inclination after getting inclination using gravity sensor or getting gravity from accelerometer with lowpass filter. If it's not flat(AR application or inclination>25 || inclination < 155) remap coordinate system from x,y to x,z. That will solve the issue.

SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remappedRM);
SensorManager.getOrientation(remappedRM, orientation);

这解决了Gimbal Lock问题,但是我在Play商店中看到的3D指南针(普通指南针由于仅以x,y映射而出现了Gimbal Lock的作用,因此无法给出正确的结果),并且这里的每个代码都存在差异当您将设备放平或屏幕指向您时.这种差异有时可达10度.我无法解决.通常差异在1-5度之间,但我有时会看到上升到10度,这是不可接受的.

This solves the Gimbal Lock, however, 3D compasses(normal compasses does not give correct results due to they are only mapped in x,y and occurs Gimbal Lock) i've seen on Play Store and every code here has a diffence when you keep your device laying flat or screen pointing at you. That difference sometimes gets up to 10 degrees. I haven't able to solve it. Mostly difference is between 1-5 degrees but i sometimes see it rise up to 10 degrees which is not acceptable.

Google从您的位置测量方位角.有代码可以找到方位.

Google measures azimuth from your location. There is a code to find bearing.

currentLocation.getBearing();

经度精度(当前位置的精度)决定着轴承的精度.

Accuracy of lat long(accuracy of your current location) is what determines accuracy of bearing.

以最精确的方式进行指南针操作的方式列表依次列出

List of ways doing a compass with the most accurate to least is in order

  1. 使用GPS/妻子(Google的融合位置)位置并从该位置获取方位
  2. 使用旋转矢量(需要磁场传感器,请检查是否可用),它是融合传感器(磁场+陀螺仪+加速度计和软件部件),并使用卡尔曼滤波器平滑值,但检查倾斜度以重新映射方向
  3. 重力/加速度计+磁场传感器.这将带有可怕的噪声,要使其平滑,您应该使用移动平均或低通滤波器(这不是隔离重力,而是使用阈值频率来防止跳高)

这篇关于如何获取高质量的指南针方向(如在Google地图中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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