Android compass accuracy - when to calibrate?

情到浓时终转凉″ 提交于 2020-12-08 07:21:20

问题


I develop an application which provides some augmented reality features using compass. I found out that sometimes I need to calibrate my compass to make it work well.

How do I know (programatically) that calibration is needed?

I mean I know how to calibrate compass using the 8-pattern figure, but I want to detect that calibration is needed and display some alert to user ("Your compass is not accurate enough, please calibrate your compass sensor.").

Is this possible, please? Thanks!


回答1:


My solution would be to use the onAccuracyChanged() method of the SensorEventListener interface.

This is how I would do :

//In SensorEventListener interface implementation    
@Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        switch(sensor.getType()){
            case Sensor.TYPE_MAGNETIC_FIELD :
                switch(accuracy) {
                    case SensorManager.SENSOR_STATUS_ACCURACY_LOW :
                        doSomething();
                        break;
                    case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM :
                        doSomethingElse();
                        break;
                    case SensorManager.SENSOR_STATUS_ACCURACY_HIGH :
                        doNothing();
                        break;
                }
                break;
            default:
                break;
        }
    }

You should also look at this answer here : https://stackoverflow.com/a/7877688/7501326

"Typically, if a device is not calibrated, you will see great variations in the azimuth value for small rotations. That is what I would be worried about."



来源:https://stackoverflow.com/questions/28175420/android-compass-accuracy-when-to-calibrate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!