For an augmented reality web app for smartphones I\'m trying to calculate the compass heading when the user is holding the device in their hand, with the screen in a vertica
I have also played some with the DeviceOrientationEvent (might adopt you formula...) and seen similar problems from time to time. You might wanna try a calibration as in this video. You could search youtube for more examples.