Device Access

Device orientation

Device motion and orientation events provide access to the built in accelerometer, gyroscope and compass in mobile devices.

These events can be used in for many purposes; for example in gaming to control the direction of character, or to determine how high a character should jump. When used with GeoLocation, it can create a more accurate turn-by-turn navigation system or provide information about where a store is.


  • Use extreme caution when deciding to use device motion or device orientation events. Unfortunately not all browsers use the same coordinate system, and may report different values under identical situations.

Which end is up?

In order to use the data returned by the device orientation and motion events, it is important to understand the values provided.

Earth coordinate frame

The Earth coordinate frame, described by the values X, Y and Z, are aligned based on gravity and standard magnetic orientation.

  • X: represents the east-west direction (where east is positive).
  • Y: represents the north-south direction (where north is positive).
  • Z: represents an up-down direction, perpendicular to the ground (where up is positive).

Device coordinate frame

The device coordinate frame described by the values x, y and z are aligned based on the center of the device.

illustration of device coordinate frame

  • x: in the plane of the screen, positive to the right.
  • y: in the plane of the screen, positive towards the top.
  • z: perpendicular to the screen or keyboard, positive extending away.

On a phone or tablet, the orientation of the device is based on the typical orientation of the screen. For phones and tablets, it is based on the device being in portrait mode. For desktop or laptop computers, the orientation is considered in relation to the keyboard.

Rotation data

Rotation data is returned as a Euler angle, representing the number of degrees of difference between the device’s coordinate frame and the Earth coordinate frame.

alpha: The rotation around the z axis and is 0° when the top of the device is pointed directly north. As the device is rotated counter-clockwise the `alpha` value increases.

beta: The rotation around the x axis and is 0° when the top and bottom of the device are equidistant from the surface of the earth. The value increases as the top of the device is tipped toward the surface of the earth.

gamma: The rotation around the y axis and is 0° when the left and right of the device are equidistant from the surface of the earth. The value increases as the the right side is tipped towards the surface of the earth.


Pete LePage

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies.