HarmonyOS 如何通过传感器数据计算朝向信息?

代码如下:

if (this.geomagnetic != null) {
  sensor.getRotationMatrix(this.gravityList, this.geomagnetic).then((data: sensor.RotationMatrixResponse) => {
    if (data != null) {
      sensor.getOrientation(data.rotation).then((data: Array<number>) => {
        let orientationData = new OrientationData()
        orientationData.sensor = type
        orientationData.accuracy = item.a?.toString()
        orientationData.orientation = data[0]?.toString()
        orientationData.orientationText = this.degreeToDirectionText(data[0])
        orientationData.time = Date.now().toString()
        if (this.orientationList != null) {
          let now = Date.now()
          if (this.lastOrientationTime == 0 || (this.lastOrientationTime ?? 0) + 1000 < now) {
            this.orientationList.push(orientationData)
            this.tryAddOrientationData(false)
            this.lastOrientationTime = now
          }
        }
      })
    }
  })
}

但是获取到的结果,却都是低于2的数值。按照映射规则,则结果都是正北。想要了解一下,HarmonyOS上的朝向信息如何计算,以及计算出来的结果要如何映射到对应的方向上?

阅读 396
logo
HarmonyOS
子站问答
访问
宣传栏