Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
PhoneGap 4 Mobile Application Development Cookbook
PhoneGap 4 Mobile Application Development Cookbook

PhoneGap 4 Mobile Application Development Cookbook: Build real-world hybrid mobile applications using the robust PhoneGap development platform

Arrow left icon
Profile Icon Zainul Setyo Pamungkas
Arrow right icon
€8.99 €32.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (4 Ratings)
eBook Oct 2015 356 pages 1st Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Zainul Setyo Pamungkas
Arrow right icon
€8.99 €32.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (4 Ratings)
eBook Oct 2015 356 pages 1st Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

PhoneGap 4 Mobile Application Development Cookbook

Chapter 2. Movement and Location – Using the Accelerometer and Geolocation Sensors

In this chapter, we will cover the following recipes:

  • Detecting device movement using the accelerometer
  • Adjusting the accelerometer sensor update interval
  • Updating a display object position through accelerometer events
  • Obtaining device geolocation sensor information
  • Adjusting the geolocation sensor update interval
  • Retrieving map data through geolocation coordinates
  • Creating a visual compass to show the device direction

Introduction

Mobile devices are incredibly powerful tools that not only allow us to make calls and send messages, but also help us navigate and identify where we are in the world, thanks to the accelerometer, geolocation, and other sensors.

This chapter will explore how we can access these sensors and make use of this exposed functionality using plugins.

Detecting device movement using the accelerometer

The accelerometer captures device motion in the x, y, and z axis direction. The accelerometer is a motion sensor that detects change (delta) in movement relative to the orientation of the current device.

How to do it…

We will use the accelerometer functionality from the plugins to monitor the feedback from the device:

  1. First, create a new PhoneGap project named accelerometer. Open Terminal or Command Prompt and run the following command:
    phonegap create accelerometer com.myapp.accelerometer accelerometer
    
  2. Add the device's platform. You can choose to use Android, iOS, or both:
    cordova platform add ios
    cordova platform add android
    
  3. Add the device-motion plugin by running the following command:
    phonegap plugin add org.apache.cordova.device-motion
    
  4. Open www/index.html and clean up unnecessary elements; so you have the following:
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            &lt...

Adjusting the accelerometer sensor update interval

The getCurrentAcceleration method obtains data from the accelerometer at the time it was called - a single call to obtain a single response object. In this recipe, we'll build an application that allows us to set an interval to obtain a constant update from the accelerometer to detect continual movement from the device.

How to do it…

We will provide additional parameters to a new method available through the PhoneGap API to set the update interval:

  1. First, create a new PhoneGap project named accelupdate. Open Terminal or Command Prompt and run the following command:
    phonegap create accelupdate com.myapp.accelupdate accelupate
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:
    cordova platform add ios
    cordova platform add android
    
  3. Add the device-motion plugin by running the following command:
    phonegap plugin add org.apache.cordova.device-motion
    
  4. Open www/index.html and clean up unnecessary elements; so you have the...

Updating a display object position through accelerometer events

Developers can make use of the accelerometer sensor and continual updates provided by it for many purposes, including motion-detection games and updating the position of an object on the screen.

How to do it…

We will use the device's accelerometer sensor on continual update to move an element around the screen as a response to device movement:

  1. First, create a new PhoneGap project named accelobject by running the following command:
    phonegap create accelobject com.myapp.accelobject accelobject
    
  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 motion plugin by running the following command:
    phonegap plugin add org.apache.cordova.device-motion
    
  4. Open www/index.html and clean up unnecessary elements. Within the body tag create two div elements. Set the first with the id attribute equal to dot. This will be the element that will move around...

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...

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...

Introduction


Mobile devices are incredibly powerful tools that not only allow us to make calls and send messages, but also help us navigate and identify where we are in the world, thanks to the accelerometer, geolocation, and other sensors.

This chapter will explore how we can access these sensors and make use of this exposed functionality using plugins.

Detecting device movement using the accelerometer


The accelerometer captures device motion in the x, y, and z axis direction. The accelerometer is a motion sensor that detects change (delta) in movement relative to the orientation of the current device.

How to do it…

We will use the accelerometer functionality from the plugins to monitor the feedback from the device:

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

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

    cordova platform add ios
    cordova platform add android
    
  3. Add the device-motion plugin by running the following command:

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

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <meta name="format-detection...
Left arrow icon Right arrow icon

Description

Developing mobile applications often feels intimidating. Especially when building cross-platform application. We have to learn a specific programming language to build an application for each platform. PhoneGap makes cross-platform mobile application development faster and easier by using web technologies such as HTML5, CSS, and JavaScript. This book gives you practical lessons on how to build a world class mobile application using PhoneGap. Whether you are a brand new to mobile application development, a web developer expert, or a seasoned mobile application developer, this book will guide you through creating hybrid mobile applications. Starting with setting up a development environment, the book moves on to utilizing a new PhoneGap command-line tool, installing plugins, and designing your application. It then moves on to concepts such as file system, storage, and local database, the book effectively lays a solid base for advanced topics. By working through the steps in each chapter, you will quickly master the features of PhoneGap. By the end of the book, you will be able to successfully build a highly functional, real-world hybrid mobile application using PhoneGap.

Who is this book for?

If you are a developer who wants to get started with mobile application development using PhoneGap, then this book is for you. Previous experience with data mining libraries will help, but is not mandatory. A basic understanding of web technologies such as HTML, CSS, and JavaScript is a must.

What you will learn

  • Set up a development environment to develop PhoneGap applications
  • Generate, build, and run applications using the PhoneGap commandline interface
  • Install plugins from the command line to add native capabilities to your application
  • Call the JavaScript API of plugins and hook into native events
  • Manipulate DOM using zepto and xuijs
  • Develop a user interface using jQuery Mobile and the Ionic framework
  • Get accustomed to using the PhoneGap Build service

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 30, 2015
Length: 356 pages
Edition : 1st
Language : English
ISBN-13 : 9781783287956
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 30, 2015
Length: 356 pages
Edition : 1st
Language : English
ISBN-13 : 9781783287956
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
PhoneGap By Example
€36.99
PhoneGap 4 Mobile Application Development Cookbook
€41.99
Mastering PhoneGap Mobile Application Development
€41.99
Total 120.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. Welcome to PhoneGap 3 Chevron down icon Chevron up icon
2. Movement and Location – Using the Accelerometer and Geolocation Sensors Chevron down icon Chevron up icon
3. Filesystems, Storage, and Local Databases Chevron down icon Chevron up icon
4. Working with Audio, Images, and Video Chevron down icon Chevron up icon
5. Working with Your Contacts List Chevron down icon Chevron up icon
6. Hooking into Native Events Chevron down icon Chevron up icon
7. Working with XUI Chevron down icon Chevron up icon
8. Working with the Ionic Framework Chevron down icon Chevron up icon
9. Ionic Framework Development Chevron down icon Chevron up icon
10. User Interface Development Chevron down icon Chevron up icon
11. Extending PhoneGap with Plugins Chevron down icon Chevron up icon
12. Development Tools and Testing Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(4 Ratings)
5 star 25%
4 star 50%
3 star 0%
2 star 25%
1 star 0%
Somu Shekar Nov 24, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Provides in depth knowledge on building hybrid mobile application. Its very good book for start off mobile application. Also covers Ionic faramwork which is build on Angluafjs, SAAS, html5. Recommended who wants to build rich/responsive hybrid app for beginners and web developers migrated to mobile application develpment
Amazon Verified review Amazon
Drew Kinney Nov 20, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
If you are interested in the nuts and bolts of PhoneGap development, this is a good read.This book gives you insight into why you would want to learn this methodological approach, along with how the process works.I recommend this for any web designer/developer who wants to get into mobile development.
Amazon Verified review Amazon
Vinay Dec 22, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Nice book. Well done!!
Amazon Verified review Amazon
Marco Ronchi Aug 05, 2016
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Il libro mi sembra scritto in fretta, manca spesso di coerenza nei vari passaggi e analizza in maniera davvero troppo superficiale l'integrazione dei vari plugin, analisi che era il motivo per cui l'avevo comprato. Deluso.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.