You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This probably doesn't answer your question... I use alpha / beta / gamma from Chrome's 'deviceorientationabsolute' event to set a compass / pitch / roll widget but I don't use that to determine screen orientation. Instead I listen to $(window).resize() (yeah, JQuery but there's a native call too) and compare width and height of a whole-screen div:
var vpWidth = $('#whole_viewport').width();
var vpHeight = $('#whole_viewport').height();
If you use the DeviceMotion (instead of DeviceOrientation) it returns values of gravity included accelerations. You can check the .ACCELERATION_INCLUDING_GRAVITY_ZIf it is close to 0 it means the device is up from the ground (not lying on the floor).
On top of that you can check the viewport orientation like @donbarthel suggested.
One thing to be careful: When your device is lying on the ground iPhone returns negative Z values where as Android returns positive. But in your case if your value is, lets say, between -10 and 10 you can assume the device is up from the ground. Regardless of an iPhone or Android.
Hi,
Do you have any idea how to do this? Currently I have something like this:
if ((newBeta > 5 && newBeta < 85) && (newGamma > -40 && newGamma < 40)) {
absoluteP.innerHTML = 'portrait';
} else if ((newBeta > -40 && newBeta < 40) && (newGamma > -85 && newGamma < -5) || ((newBeta > -40 && newBeta < 40) && (newGamma > 5 && newGamma < 85))) {
absoluteP.innerHTML = 'landscape';
}
The text was updated successfully, but these errors were encountered: