Book Image

PhoneGap Beginners Guide (third edition)

Book Image

PhoneGap Beginners Guide (third edition)

Overview of this book

Table of Contents (22 chapters)
PhoneGap Beginner's Guide Third Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Related Plugin Resources
Index

Compass


The PhoneGap Compass API allows you to obtain the direction that the device is pointing to. The compass is a sensor that detects the direction or heading in which the device is pointed and returns the heading of the device in degrees using values from 0 to 359.99. The Compass API works similarly to the Accelerometer API; in fact, you can read the current device heading or you can define a watcher in order to continuously read the heading value.

The Compass API is available on the compass property of the navigator object and exposes the following functions:

  • compass.getCurrentHeading: This reads the current compass heading through a handler

  • compass.watchHeading: This reads the compass heading at a specific time interval through a handler and returns a reference to it

  • compass.clearWatch: This stops a previously defined time interval reading handler

The getCurrentHeading and watchHeading functions accept very similar arguments; the only difference is the last argument of the watchHeading...