【问题标题】:How to use SensorEventListener to determine direction phone is facing relative to magnetic north如何使用 SensorEventListener 确定手机相对于磁北的方向
【发布时间】:2013-07-02 06:14:24
【问题描述】:

我正在尝试编写一个实现SensorEventListener 的类,以确定手机摄像头朝向的方向(Galaxy S3),以从磁北向东的度数为单位。以下是我正在使用的传感器:

  public void start()
  {
    mManager.registerListener(this, mManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME);
    mManager.registerListener(this, mManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),  SensorManager.SENSOR_DELAY_GAME);
  }

我相信我正在寻找方位角,它在调用SensorManager.getOrientation(mRotationMatrix, mOrientation); 后存储在mOrientation[0] 中。

但是,当我这样做时,结果似乎是围绕重力旋转,而不是从磁北旋转。我做错了吗?

【问题讨论】:

    标签: android sensors android-sensors


    【解决方案1】:

    您需要在调用getOrientation 之前调用remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR); 以获取后置摄像头的方向。 azimuth 是相对于磁北的方向。 这相当于将设备坐标系的负Z轴投影到世界东西北平面,然后计算投影向量与北轴的夹角。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      相关资源
      最近更新 更多