I'm making a compass app for Android and I've managed to capture the azimuth by using the gyroscope, accelerometer, and magnetometer (see here for the tutorial I used). Unfortunately, the compass reading only functions when the device is placed parallel to the ground (ie, flat on a table/the palm of my hand, etc.). Whenever I tilt the device up to a fully upright position (with the screen facing me), the compass simply gives out a wrong reading. I'm assuming that this is because the axes change when the device's orientation itself changes. How do I prevent this from happening? I would like the compass to work in BOTH these two positions: parallel to the ground AND the fully upright position. How do I go about doing this? If someone could give me a push in the right direction, that would be super helpful.
Thanks for all your help! :D