You need both the Magnectic field
and Accelerometer
to calculate the compass direction. You can see why if you read the source code of the getRotationMatrix
or for a more verbose explanation see Convert magnetic field X, Y, Z values from device into global reference frame
If you stand at the same place, the magnetic field does not change. That is the magnetic field vector returned in onSensorChanged should change very little. It is not the vector that change but the coordinates of the device that change. It is the meaning of what is being calculate and call the "compass direction"
that confuses you. In this case the direction to be used as the "compass direction"
is the direction of the y coordinate
. Thus when you hold the phone vertically, the y coordinate
points to the sky or the ground and it does not make sense to talk about "compass direction"