我得到我的手机方位的SensorManager.getOrientation给人很不稳定的结果
SensorManager.getOrientation
帮助,但结果是非常不稳定的,像+ -8度,有FO过滤的结果会好方法?
这是我得到的值:
public void onSensorChanged(SensorEvent event)
{
switch (event.sensor.getType()){
case Sensor.TYPE_ACCELEROMETER:
aValues = event.values.clone();
break;
case Sensor.TYPE_MAGNETIC_FIELD:
mValues = event.values.clone();
break;
}
float[] R = new float[16];
float[] orientationValues = new float[3];
if(aValues == null || mValues == null)
return;
if(!SensorManager.getRotationMatrix (R, null, aValues, mValues))
return;
float[] outR = new float[16];
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_Z, SensorManager.AXIS_MINUS_X, outR);
SensorManager.getOrientation (outR, orientationValues);
orientationValues[0] = (float)Math.toDegrees (orientationValues[0]);
orientationValues[1] = (float)Math.toDegrees (orientationValues[1]);
orientationValues[2] = (float)Math.toDegrees (orientationValues[2]);
}
您可以使用System.arraycopy代替event.values.clone()的性能来获取。在这里你总是创建新的对象,这是非常昂贵的。 – Geoffroy