查找设备的标题

时间:2014-06-25 04:36:41

标签: android android-sensors magnetometer

我需要找到垂直持有的Android设备的标题(就北方或西方的度数而言)(例如:Heading)。我访问了地磁传感器返回的sensor.event [2]值,发现它们在1到35之间变化,因为我完全围绕垂直轴旋转设备。如何将此值转换为标题?非常简短的解释或链接将不胜感激。

1 个答案:

答案 0 :(得分:0)

查看SensorManager.getOrientation它围绕3个轴返回3个角度。

Computes the device's orientation based on the rotation matrix.

When it returns, the array values is filled with the result:

    values[0]: azimuth, rotation around the Z axis.
    values[1]: pitch, rotation around the X axis.
    values[2]: roll, rotation around the Y axis.

The reference coordinate-system used is different from the world coordinate-system defined for the rotation matrix:

    X is defined as the vector product Y.Z (It is tangential to the ground at the device's current location and roughly points West).
    Y is tangential to the ground at the device's current location and points towards the magnetic North Pole.
    Z points towards the center of the Earth and is perpendicular to the ground.

您需要使用地磁和加速计传感器来输入数据以获得旋转矩阵。查看SensorManager以获取更多信息