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

Obtaining device geolocation sensor information


Geolocation and the use of Global Positioning System (GPS) allow developers to create dynamic real-time mapping, positioning, and tracking applications. Using the available geolocation methods, we can retrieve a detailed set of information and properties to create location-aware applications. We can obtain the user's location via the mobile data network, Wi-Fi, or directly from the satellite.

How to do it…

We will use the geolocation functionality from the geolocation plugin's API to monitor the feedback from the device and obtain the relevant location information, as follows:

  1. First, create a new PhoneGap project named geolocation. Open Terminal or Command Prompt and run following command:

    phonegap create geolocation com.myapp.geolocation geolocation
    
  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...