すみません 。あなたの助けが必要です 。私はaugumentetの現実のためにオリエンテーション(s / n / e / w)を取得したいのですが、間違った結果(センサーからの間違ったデータ)を示しています。私は横向きを使用しています。それは私のコードです(loadnewsensordataで、磁場センサーと加速度計センサーからデータをロードします)-
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 < 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] < 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();
}
}