I\'m making a map app, including the location arrow that shows you which way you\'re facing, like so:
You should take the pitch and determine if the user is close to holding the phone vertically up.
i chose that after 45 degree pitch up or down from flat on table, the coordinate system should be remapped.
if (Math.round(Math.toDegrees(-orientation[1])) < 45 && Math.round(Math.toDegrees(-orientation[1])) > -45) {
//do something while the phone is horizontal
}else{
//R below is the original rotation matrix
float remapOut[] = new float[9];
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, remapOut);
//get the orientation with remapOut
float remapOrientation[] = new float[3];
SensorManager.getOrientation(remapOut, remapOrientation);
It has worked out pretty well. Let me know if anyone can suggest an improvement on this. Thanks.