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
About the Authors
About the Reviewers
Related Plugin Resources

The PhoneGap Geolocation API

The Geolocation API is not a part of the HTML5 specification, but it is tightly integrated with mobile development. The PhoneGap Geolocation API and the W3C Geolocation API mirror each other; both define the same methods and relative arguments. There are several devices that already implement the W3C Geolocation API; for those devices, you can use native support instead of the PhoneGap API.


As per the HTML specification, the user has to explicitly allow the website or the app to use the device's current position.

The Geolocation API is exposed through the geolocation object child of the navigator object and consists of the following three methods:

  • getCurrentPosition(): This returns the device position

  • watchPosition(): This watches for changes in the device position

  • clearWatch(): This stops the watcher for the device's position changes

The watchPosition() and clearWatch() methods work in the same way that the setInterval() and clearInterval() methods work; in...