There is a reason most devices use GPS (which already has horrible dilutiuon when it comes to altitude calculation) or even a barometric system to calculate their altitude : Magnetic measurements are terribly unstable and perceptive to interference from outside, not to mention that the planet does not have a completely uniform magnetic field, and that it runs lateral with the surface rather than in a straight angle with it.
If you managed to get a decent altitude reading with a magnetometer, i think you would be elligable for a prize in the fields of mathematics, physics and programming.