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

Creating a visual compass to show the device direction


The geolocation and accelerometer plugins' API provides developers with the ability to receive coordinate and heading information from the device. We can use this information to build a custom compass tool that responds to the device movement.

How to do it…

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

    phonegap create compass com.myapp.compass compass
    
  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 device-orientation, device-motion, and geolocation plugins by running the following command:

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

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" /&gt...