O'Reilly logo

WordPress Mobile Applications with PhoneGap by Yuxian Eugene Liang

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

Capturing geolocation using PhoneGap API

In this section, we will quickly run through how we can capture geolocation information using the PhoneGap's API. We will be modifying some code from PhoneGap's official documentation at http://docs.phonegap.com/en/1.9.0/cordova_geolocation_geolocation.md.html#geolocation.getCurrentPosition.

Let's see how we can start:

  1. Create a new HTML file and name it phonegap.html. Save it under your assets/www folder. Copy and paste the following code into the phonegap.html file:
    <!DOCTYPE html> <html> <head> <title>Device Properties Example</title> <script type="text/javascript" charset="utf-8"src="cordova-1.9.0.js"></script> <script type="text/javascript" charset="utf-8">// Wait for Cordova to load//document.addEventListener("deviceready", ...

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