此答案由使用here類啓發:
YOUT應該有onSensorChanged方法在SensorEventListener
@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
}
}
要獲得學位正北你可以用this answer
我想您的問題可能已被回答[這裏](http://stackoverflow.com/a/5518318/7071399)乾杯 –
嗨,我知道這個職位。但它並不能幫助我,因爲我需要的是一個新的座標系,不僅僅是這個帖子中的一個值。 – pixie