Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using geolocation


We can use Cordova's org.apache.cordova.geolocation plugin to access the hardware's geolocation services.

Getting ready

Begin by installing the geolocation plugin using the following command:

cordova plugin add org.apache.cordova.geolocation

Once installed, we can use Cordova's navigator.geolocation object to access the hardware's geolocation services.

How to do it...

To access the device's geolocation information, we use the getCurrentPosition() method:

  1. Add the following HTML to index.html:

    <div data-role="view" id="app-location" 
      data-title="Location"
      data-layout="layout">
      <h3>Location</h3>
      <p>
        <a data-role="button"
          data-click="app.demos.location.onFetchLocation">
          Fetch Location</a>
      </p>
      <p id="location-status" style="display: none;">
        <i>Fetching position...</i>
      </p>
      <p id="location-error" style="display: none;"></p>
      <ul id="location-info" data-role="listview...