Merci pour ta réponse ,
Mais lorsqu'on parle de SensorManager.getOrientation():
getOrientation (float[] R, float[] values)
avec R :
rotation matrix see getRotationMatrix(float[], float[], float[], float[]).
et :
1 2 3
| values[0]: azimuth, rotation around the -Z axis, i.e. the opposite direction of Z axis.
values[1]: pitch, rotation around the -X axis, i.e the opposite direction of X axis.
values[2]: roll, rotation around the Y axis. |
Donc la plupart sur les discusions :Obtenez angle de l'appareil en utilisant la fonction GetOrientation
il propose la solution suivante:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public void onAccuracyChanged(Sensor sensor, int accuracy) { }
float[] mGravity;
float[] mGeomagnetic;
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
mGravity = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
mGeomagnetic = event.values;
if (mGravity != null && mGeomagnetic != null) {
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
if (success) {
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
azimut = orientation[0]; // orientation contains: azimut, pitch and roll
}
}
} |
Donc le code source proposé : SensorManager.getOrientation(R, orientation);
j'ai déjà utiliser ce code ,et les résultats obtenue :
1-le GSM est a plat vecrtical --> azimuth=37°.
2-En tournant le GSM Horizontalement de 90° --> azimuth=-111°.
Donc la différence (111-37) est 74° !!!! (mais normalement je dois obtenir 90°)
Donc j'ai deux questions :
1-le code source est bon ?
2- pourquoi 74° ?
Merci d'avance
Partager