Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Adjusting the geolocation sensor update interval


Through the use of the getCurrentPosition method, we can retrieve a single reference to the device location using GPS coordinates. In this recipe, we'll create the functionality to obtain the current location based on a numeric interval to receive constantly updated information.

How to do it…

We are able to pass through an optional parameter containing various arguments to set up interval and improve accuracy:

  1. First, create a new PhoneGap project named geoupdate by running the following command:

    phonegap create geoupdate com.myapp.geoupdate geoupdate
    
  2. Add the device platform. You can choose to use Android, iOS, or both:

    cordova platform add ios
    cordova platform add android
    
  3. Add the geolocation plugin by running the following command:

    phonegap plugin add org.apache.cordova.geolocation
    
  4. Open www/index.html and clean up unnecessary elements; so you have the following:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf...