Device Orientation - when is the device flipped?

I am trying to figure out how when a device is flipped over.

for an iPhone running iOS8, the window.onorientationchange doesn’t seem to go to 180 (its either 90, 0, or -90).

Do I need to hit the accelerometers directly or is there a way for the phone to tell me?
Any advice?

This is what I ended up doing so far for future people:


with code like this, its able to detect the flipping:

function onSuccess(acceleration) {
    document.getElementById("orientation-dg").innerHTML = acceleration.y;

  if (acceleration.y > 0)
    document.getElementById("orientation").innerHTML = '0';
    document.getElementById("orientation").innerHTML = '180';

function onError() {

var options = { frequency: 500 };  // Update every 3 seconds

var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);

Hmm, seems to work for me.

Any way, if you’re going to be using the plugin, you may want to checkout the ng-cordova plugin for it.

Is there any example about using ng-cordova device orientation ? i could not get landscape at wp8, the example code from the repository can be used where at the app.js? how to make it act globally into my app ? so any time i change the direction the app will follow.

1 Like