Book Image

Sencha Touch Cookbook, Second Edition

By : Ajit Kumar
Book Image

Sencha Touch Cookbook, Second Edition

By: Ajit Kumar

Overview of this book

<p>Sencha Touch is one of the most popular HTML5 and JavaScript frameworks for building touch-based mobile devices. Using Sencha Touch, you can create applications for touch mobile devices with ease, and once created, the same application works on multiple platforms – iOS, Android, Blackberry – without having to change anything.</p> <p>Sencha Touch Cookbook, Second Edition is a practical, hands-on guide with easy to follow recipes that provide you with clear, step-by-step instructions, which will help you take complete advantage of the power of Sencha Touch 2 and will help you to build amazing applications for the mobile world.</p> <p>Sencha Touch Cookbook, Second Edition starts by showing you how to set up your project for development, then walks through building, packaging, and running it in a browser, emulator, or a real device. With the groundwork set, the subsequent recipes of the book take you through the different UI components offered by the framework and explains how to use them, when to use them, and, if needed, how to extend them for your own application need.</p> <p>You will also learn how to model your client side data, load data from different data sources, and use them on the data-centric UI components. The later parts of the book cover the practical day-to-day problems like how to create a custom view, how to take your application offline and support automatic sync, how to utilize the Geolocation to learn more about the user, how to utilize device features such as camera, contact, orientation, and how to link your application behaviour with the device buttons such as Back, Search, and so on. At the end, the book shows you how to create native packages without using PhoneGap/Cordova using Sencha Cmd.</p> <p>Using this book, you will learn everything about using Sencha Touch classes and components to build mobile applications that can run across multiple platforms.</p>
Table of Contents (17 chapters)
Sencha Touch Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Tracking direction and speed


The Geolocation object in Sencha Touch provides properties that we can use to figure out the direction and speed at which we are moving. This could be useful in applications where you may want to suggest to the user the nearest petrol pump based on his direction. In this recipe, we will look at the use of related properties.

Getting ready

Make sure that you have set up your development environment by following the recipes outlined in Chapter 1, Gear Up for the Journey.

Make sure that you have the ch09 folder created inside the www folder.

How to do it...

Carry out the following steps:

  1. In the locationupdate event handler, add the following line of code:

    alert('Heading:' + geo.getHeading() + ': Speed:' + geo.getSpeed());
  2. Deploy and access it from the device of your choice.

How it works...

The preceding code uses the two important properties of the Geolocation class: heading and speed. The heading property gives the direction of travel of the device. It is specified in nonnegative...