Device Orientation & Motion

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

These events can be used for many purposes; in gaming, for example, to control the direction or action of a character. When used with geolocation, they can help create more accurate turn-by-turn navigation or provide information about a specific location.

Summary

  • Detect which side of the device is up and how the device is rotating.
  • Learn when and how to respond to motion and orientation events.

Which end is up?

To use the data that the device orientation and motion events return, it is important to understand the values provided.

Earth coordinate frame

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

Coordinate system
X Represents the east-west direction (where east is positive).
Y Represents the north-south direction (where north is positive).
Z Represents the up-down direction, perpendicular to the ground (where up is positive).

Device coordinate frame