How to detect device rotation in Cordova?

Viewed 2179

I would like to detect a live device rotation (not orientation, rotation in degrees) with Cordova. I used device motion but I get a bunch of acceleration x y and z values, how can I calculate rotation from this?

I would like to detect a full 360 degree rotation (imagine putting the device on a stick [or pendulum], and then hit it so it swings).

Thanks!

4 Answers

You calculate the device's "live rotation" by using the acceleration x y and z values.

To use your pendulum analogy, assuming you know for sure the device will always be swinging left and right facing the user (ie traveling on the x-axis), you can use the X value.

Keep in mind you will not get degree values. Last time I checked, iOS return 0 for upright (portrait) then -9 to 9 when rotating from one landscape to the other.

Related