传感器数据与真北android有关
我正在使用,以便从不同的传感器(更具体地说:旋转向量、重力、陀螺仪、线性加速度)获取应用程序的数据。现在,我知道在iOS中有所谓的,它给出了所有传感器关于正北的值,而z轴总是垂直的传感器数据与真北android有关,android,android-sensors,Android,Android Sensors,我正在使用,以便从不同的传感器(更具体地说:旋转向量、重力、陀螺仪、线性加速度)获取应用程序的数据。现在,我知道在iOS中有所谓的,它给出了所有传感器关于正北的值,而z轴总是垂直的 我在Android中找不到类似的东西,所以我想手动转换坐标系。我也在考虑使用。然而,我仍然不知道如何获得关于真北的数据。以前有人必须处理类似的事情吗 这个答案的灵感来自所使用的课程: 您应该在SensorEventListener中具有onSensorChanged方法 @Override publi
我在Android中找不到类似的东西,所以我想手动转换坐标系。我也在考虑使用。然而,我仍然不知道如何获得关于真北的数据。以前有人必须处理类似的事情吗 这个答案的灵感来自所使用的课程: 您应该在SensorEventListener中具有onSensorChanged方法
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
//get the rotation matrix from the sensor (this will be using the magnetic north)
SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
//change the coordinate system (your new matrix is in the variable mChangedRotationMatrix)
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y,
SensorManager.AXIS_MINUS_X, mChangedRotationMatrix);
//get the orientationMatrix of your new coordinate system
SensorManager.getOrientation(mChangedRotationMatrix, mOrientation);
//get the magnetic heading
float magneticHeading = (float) Math.toDegrees(mOrientation[0]);
//adjust accordingly by calculating the true north with either the "computeTrueNorth" method available the above link or the method used in the link below
}
}
你可以使用来获得以度表示的正北方向。我想你的问题可能已经得到了回答。我知道那篇文章。但这对我没有帮助,因为我需要的是一个新的坐标系,而不仅仅是像那篇文章中那样的值。