facebook

Acquiring GPS Location in a MyEclipse PhoneGap App

This tutorial focuses on getting a user’s GPS location using the Cordova/PhoneGap Geolocation plugin. 

*PhoneGap projects require MyEclipse 2015.

In this tutorial, you will learn how to:

  • Add the Geolocation plugin to a project
  • Add code to implement geolocation services
  • Test the project

Note: Mobile development was removed in MyEclipse 2016. This tutorial only applies to MyEclipse 2015.

1. Add the Geolocation Plugin to a Project

  1. Create a new PhoneGap project if you don’t already have one.
  2. If you didn’t add the plugin when you created the project, right-click the project, and select PhoneGap>Add/Install Plugin. 
    GPS location - adding plugin
    Adding a plugin
  3. Search for Geolocation, and select the org.appache.cordova.geolocation plugin.
    GPS location pluginSelecting a plugin

2. Access Plugin Documentation

You can find documentation for plugins inside the plugins folder structure in the index.md file and is available in multiple languages.

plugin doc
Plugin documentationInside the documentation there is license information, Supported Platforms, Methods, Objects and Examples. Using the supplied examples is a great way to learn how to implement the plugins. 

3. Add Code for Implementing Geolocation Services

The project’s js folder contains the index.js file. This file includes customizable default initialization code for the project.

  1. Double-click index.js to open it in the editor. 
  2. Copy the example code from the index.md file.
    GPS location - example code
    Copying example code
  3. Paste this code into the app.initialize device ready function in the index.js file.
    GPS location - example code
    Code pasted into index.js

4. Test the GPS Location Project

  1. Right-click the project, and select PhoneGap>Preview App in Mobile Web Simulator.
  2. Select the platform to use for testing.

    The Mobile Web Simulator opens with your project running. On start up, the project opens an alert box displaying the user’s current GPS location.
    GPS location - testing
    GPS location information when testing project