我在帮助下获得手机定位
SensorManager.getOrientation
但结果非常不稳定,比如 +-8 度,有什么好的方法可以过滤结果吗?
这就是我获取值的方式:
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]);
}