我开发了一个使用指南针提供一些增强现实功能的应用程序。我发现有时我需要校准我的指南针以使其正常工作。
我怎么知道(以编程方式)需要校准?
我的意思是我知道如何使用 8 模式图校准罗盘,但我想检测到是否需要校准并向用户显示一些警报(“您的罗盘不够准确,请校准您的罗盘传感器。”)。
请问这可能吗?谢谢!
我已经搜索了一段时间关于如何获得最准确的设备方位角并想出了这个:
//Activity members
private SensorManager sensorManager;
private float mAzimuth = 0.0f;
private float[] mRotation = null;
private float rMat[] = new float[16];
private float orientation[] = new float[3];
//Later inside the Activity: Rotation Listener
SensorEventListener rotationListener = new SensorEventListener() {
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
mRotation = event.values.clone();
if (mRotation != null) {
float RmatVector[] = new float[16];
SensorManager.getRotationMatrixFromVector(RmatVector, mRotation);
SensorManager.remapCoordinateSystem(RmatVector, SensorManager.AXIS_X, SensorManager.AXIS_Z, rMat);
SensorManager.getOrientation(rMat, orientation);
mAzimuth = …
Run Code Online (Sandbox Code Playgroud)