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
- Create a new PhoneGap project if you don’t already have one.
- If you didn’t add the plugin when you created the project, right-click the project, and select PhoneGap>Add/Install Plugin.
- Search for Geolocation, and select the org.appache.cordova.geolocation 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.
Inside 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.
- Double-click index.js to open it in the editor.
- Copy the example code from the index.md file.
- Paste this code into the app.initialize device ready function in the index.js file.
4. Test the GPS Location Project
- Right-click the project, and select PhoneGap>Preview App in Mobile Web Simulator.
- 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.