I'm trying to read absolute DeviceOrientation event values to create HTML5 compass Mobile Web App.
If I'm using this code, I can get alpha, beta and gamma values without a problem:
window.addEventListener('deviceorientation', function(event) {
alpha = event.alpha;
beta = event.beta;
gamma = event.gamma;
});
However, those values aren't helpful to me because I need to get absolute values to find exact position of North etc. I've found this article which explains how to use absolute values of event.
When I change code to this:
window.addEventListener('deviceorientationabsolute', function(event) {
alpha = event.alpha;
beta = event.beta;
gamma = event.gamma;
var absolute = event.absolute;
});
Alpha, beta and gamma values are set to null. This is strange to me, because event.absolute value is set to true. According to that, event values should be displayed.
Anyone has or had any similar problems? Any help would be appreciated; also if there is some working example of HTML5 Compass App it would be helpful to post it here.
Thank you in advance!
Try to force AddEventListenerOptions
value to true, like this:
deviceOrientationEvent: function(event){
console.log(event.alpha);
};
window.addEventListener("deviceorientationabsolute", deviceOrientationEvent, true);
Try this snippet:
deviceOrientationEvent: function(event){
console.log(event.alpha);
};
window.addEventListener("deviceorientationabsolute", deviceOrientationEvent, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With