5. Compass

The Compass API allows a Cordova application to determine the device’s heading along a two dimensional plane roughly corresponding with the surface of the Earth. An application would use this API to measure the device’s heading and update a compass image, map or some other aspect of the application based on the heading.

Many modern smartphones have a physical compass (on a chip) and the API simply queries the chip and returns an angle between 0 and 360 indicating the direction the device is pointing. A value of 0 indicates the device is pointing North, 90 indicates it is pointing east, 180 refers to South and 270 refers to West.


While most modern smartphones have a compass, not all of them do. iPhone devices have always had one, ...

Get Apache Cordova API Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.