Android中指南针的真实和磁性标题?

时间:2014-01-30 11:02:11

标签: java android android-sensors

我想在android中获得指南针的真实和磁性标题。

我已阅读了很多教程,但未提供所需的输出。

它只是标题。

我的代码在这里......

public class MainActivity extends Activity implements SensorEventListener {


// device sensor manager
private SensorManager mSensorManager;

TextView tvHeading;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    // TextView that will tell the user what degree is he heading
    tvHeading = (TextView) findViewById(R.id.tvHeading);

    // initialize your android device sensor capabilities
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
}

@Override
protected void onResume() {
    super.onResume();

    // for the system's orientation sensor registered listeners
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_GAME);
}

@Override
protected void onPause() {
    super.onPause();

    // to stop the listener and save battery
    mSensorManager.unregisterListener(this);
}

@Override
public void onSensorChanged(SensorEvent event) {

    // get the angle around the z-axis rotated
    float degree = Math.round(event.values[0]);

    tvHeading.setText("Heading: " + Float.toString(degree) + " degrees");
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // not in use
}
}

此代码为指南针提供准确的值。

如何修改此代码以获得磁航向和真实航向?

这里缺少什么?

任何人都可以帮助我。

由于

0 个答案:

没有答案