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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.