Book Image

JavaScript Mobile Application Development

Book Image

JavaScript Mobile Application Development

Overview of this book

Table of Contents (15 chapters)
JavaScript Mobile Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Compass


The compass plugin provides access to the device's compass in order to detect the direction (heading) that the device is pointed to (the compass measures the heading in degrees from 0 to 359.99, where 0 represents north). In order to use the compass in our Apache Cordova project, we need to use the following cordova plugin add command:

>cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation.git

Demo

In order to access the compass demo, you need to click on the Compass list item. You will be introduced to the Compass page. Then, you can click on the Start Watch Heading button in order to start watching the compass heading. You will be able to get the heading value, as shown in the following screenshot:

The Compass page in action

You can click on the Stop Watch Heading button to stop watching the compass heading at any time.

The HTML page

The following code snippet shows the "compass" page:

<div data-role="page" id="compass">
    <div data...