Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

13. Compass > Getting Device Heading

Getting Device Heading

To query the device’s orientation, simply call the following method:

navigator.compass.getCurrentHeading(successFunction, 
  errorFunction);

Passed to the API are the names of two functions that are called depending on whether the API is returning a result. The successFunction is called when a reading has been successfully made, and the errorFunction is called when there is an error reading the compass.

When called, the successFunction is passed the compassHeading object, which consists of the following components:

magneticHeading: The device’s current heading in degrees ranging from 0 to 359.99.

trueHeading: The device’s current heading relative to the geographic North Pole in degrees ranging from 0 to 359.99. A negative value indicates that a value could not be determined.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint