3

我在帮助下获得手机定位

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]);
    }
4

1 回答 1

0

只需通过计算平均值来缓冲值(有许多不同的计算可能性:http ://en.wikipedia.org/wiki/Average#Types )。还要考虑缓冲越多,应用程序对更改的反应就越慢!

于 2012-01-24T15:53:13.773 回答