How to Monitor Geographic Location Updates in WRT Widget

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code Example
Installation file: Media:Geolocation_test.zip
Tested with
Devices(s): Nokia N97
Keywords: watchPosition(), geolocation, Platform Service 2.0
Created: vasant21 (16 Jan 2010)
Last edited: hamishwillee (05 Jul 2012)



  • This article and code snippet below explains how one can monitor changes in Geographic Location in a Widget using geolocation service object in Nokia Platform Services 2.0.
  • Before we start with the article, there are two ways of including Platform Services 2.0 support to the widget:
 - Installing platformservices_v2_0_beta.SIS, will add the JavaScript library to a common location
   (c:\system\widgetlibs\platformservices.js) that can be accessed by any widget.
 - Including the JavaScript library platformservices.js directly in a widget.
  • We will use the second option for simplicity, and ease of testing the widget.
  • In the code below we try to monitor the changes in the device geographic location and display it on screen, for that we will use watchPosition api.


<script type="text/javascript" src="platformservices.js" charset= "utf-8" />
<script language="javascript">
var so = null;
var tid = ""
// Callback function called whenever change in location is detected.
function onLocationUpdate( newLocation ){
var lon = newLocation.coords.longitude;
var lat = newLocation.coords.latitude;
alert("Location Changed : \n Longitude: " + lon + "\n Latitude: " + lat);
//Error handling callback function for watchPosition.
function onLocationError( error ){
alert("Error getting Location Updates: " + error.message );
// On exit lets just clear the ongoing watch for location changes if any.
window.widget.onexit = function() {
if( tid ){
// Lets first create geolocation object.
so = com.nokia.device.load("", "com.nokia.device.geolocation");
// Lets start getting location updates.
var tid = so.watchPosition(onLocationUpdate, onLocationError);
alert("Error : " + e);
<body>Location Updates Test Widget</body>

Sample Widget

Media:Geolocation_test.zip is a sample widget - install and launch.

How to Test

  • Launch the widget, it will start monitoring location updates and will display the location if changes are detected in the device location.
This page was last modified on 5 July 2012, at 02:54.
60 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.