Code Example‎ > ‎


Choose, File --> new project --> project 
Then select Droidget wizards --> project from New Project dialog  
Fill out Project name field, etc  In the Feature section , Click on Add and select geolocation feature "".  
Then click Finish .
Droidget project with the given name will be created and displayed in the project explorer.

After finished creating project, Bondi Feature <feature name="" /> will be appeared in the config.xml file as follows.

<?xml version="1.0" encoding="UTF-8"?>
<widget id="GPSSample_1279453579736" version="1.0" width="300" height="150">
    <content src="index.html" type="text/html"/>
    <description>Sample Widget with GPS</description>
    <author url="">GClue</author>
    <icon src="icon.png"/>
    <feature name="" />

Create JavaScript File

create a new folder called js and under that folder create a new file and name it as "script.js".
Then add the following functions.

function buttonHandler(){
    document.getElementById("divMsg").innerHTML = "Searching";  
    bondi.geolocation.getCurrentPosition(onPositionSuccess, onPositionError, {timeout:40000});

// this function will handle each position updates
function onPositionSuccess(position) {
    lat = position.coords.latitude;
    lon = position.coords.longitude;
    document.getElementById("divMsg").innerHTML = "lat:" + lat + "<br>" + "lon:" + lon;  

// this function will handle each error in position updates
function onPositionError(error) {
    document.getElementById("divMsg").innerHTML = "Error";

Edit index.html

Change the index.html file content as follows. 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <title>GPS Sample</title>
    <script type="text/javascript" src="js/script.js"></script>
    <div id="divMsg" style="color: yellow; height: 3.0em; font-size: 1em; "></div>
    <input type="button" id="formBtn" value="Get GPS" onclick="buttonHandler()"/>


Selecte the project from Project Explorer and Click Droidget>>Packaging

Widget Installation

Now save and deploy the project
  • From the eclipse menu select Droidget --> packaging
  • Then Droidget-->install packaging
  • upload the Widget to web server and update the download.html file as follows. Then access the download.html from the smart phone and install the widget from URI.

    <a href="droidget://">GPSSample</a><br>


after installation , output will be like this.