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

Time for action – showing device position with Google Maps

Get ready to add a map renderer to the PhoneGap default app template. Execute the following steps:

  1. Open the command-line tool and create a new PhoneGap project named MapSample:

    $ cordova create MapSample
  2. Change the working directory to the newly created project:

    $ cd MapSample
  3. Add the required platform to the project. For example, we will add Android to this project:

    $ cordova platform add android
  4. Add the Geolocation API plugin using the following command:

    $ cordova plugin add cordova-plugin-geolocation
  5. Go to the www folder, open the index.html file, remove all the existing content, and add a div element with the id value as #map inside the body tag:

    <div id='map'></div>
  6. Include the cordova.js file that will be added to the app at runtime:

    <script type="text/javascript" src="cordova.js"></script>
  7. Add a new script tag to include the Google Maps JavaScript library. Replace the YOUR_API_KEY value with your actual...