Tag: 数字罗盘

无论屏幕方向如何,如何获得正确的方位(磁方向)?

无论当前的屏幕方向(横向或纵向),我都希望获得当前的磁性方向。 我找到了这个例子,但它不是独立的方向,对吧? 这对我也没有帮助。 我也读过http://android-developers.blogspot.de/2010/09/one-screen-turn-deserves-another.html 。 这是我目前采用的方法,我不想使用(简称): mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); private SensorEventListener sensorEventListener = new SensorEventListener() { public void onSensorChanged(SensorEvent event) { /* Get measured value */ float current_measured_bearing = (float) event.values[0]; /* Compensate device orientation */ switch (((WindowManager) getSystemService(WINDOW_SERVICE)) .getDefaultDisplay().getRotation()) { case Surface.ROTATION_90: current_measured_bearing = current_measured_bearing + 90f; break; case Surface.ROTATION_180: current_measured_bearing = current_measured_bearing – 180f; break; […]