O'Reilly logo

CoffeeScript Application Development Cookbook by Mike Hatfield

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required