title: Android.Orientation Wrong data from sensors,
body: <p>Excuse me . I need your help . I want to get Orientation (s/n/e/w) for augumentet reality , but it show me wrong results(wrong data from sensor) . I use landscape orientation. it is my code(in loadnewsensordata i load data from magnetic field sensor and accelerometer sensor) -    </p>
  
  <pre><code>    private float[] calculateOrientation() {
  
          float[] values = new float[3];
          float[] I = new float[16];
          values[0] = 0;
          values[1] = 0;
          values[2] = 0;
          float[] R = new float[16];
          float[] outR = new float[16];
          for (int i = 0; i &lt; R.length; i++) {
              R[i] = 0;
              outR[i] = 0;
          }
  
          Display display = parrent.getWindowManager().getDefaultDisplay();
          int deviceRot = display.getRotation();
  
  
          SensorManager.getRotationMatrix(R, null, accelData, magnetData);
          switch (deviceRot) {
              case Surface.ROTATION_0:
                  SensorManager.remapCoordinateSystem(R,
                          SensorManager.AXIS_X, SensorManager.AXIS_Z,
                          outR);
                  break;
  //                 rotated left (landscape - keys to bottom)
              case Surface.ROTATION_90:
                  SensorManager.remapCoordinateSystem(R,
                          SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
                          outR);
                  break;
              // upside down
              case Surface.ROTATION_180:
                  SensorManager.remapCoordinateSystem(R,
                          SensorManager.AXIS_X, SensorManager.AXIS_Z,
                          outR);
                  break;
              // rotated right
              case Surface.ROTATION_270:
                  SensorManager.remapCoordinateSystem(R,
                          SensorManager.AXIS_MINUS_Z, SensorManager.AXIS_X,
                          outR);
                  break;
  
              default:
                  break;
          }
          SensorManager.getOrientation(outR, values);
  
          // Convert from Radians to Degrees.
          values[0] = (float) Math.toDegrees(values[0]);
          values[1] = (float) Math.toDegrees(values[1]);
          values[2] = (float) Math.toDegrees(values[2]);
          if (values[0] &lt; 0) {
              values[0] = 360 + values[0];
          }
          return values;
      }
  
      public void onSensorChanged(SensorEvent event) {
  
          loadNewSensorData(event);
          tw1 = (int) calculateOrientation()[0] + " ";
          parrent.viewBearingOnDisplay(tw1);
      }
  
  
  private void loadNewSensorData(SensorEvent event) {
      final int type = event.sensor.getType(); //Определяем тип датчика
  
      if (type == Sensor.TYPE_ACCELEROMETER) { //Если акселерометр
          accelData = event.values.clone();
      }
  
      if (type == Sensor.TYPE_MAGNETIC_FIELD) { //Если геомагнитный датчик
          magnetData = event.values.clone();
      }
  
  }
  </code></pre>