Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Obtaining location information using Symbian Web Runtime

From Wiki
Jump to: navigation, search

This code snippet demonstrates how to use the Location Service API of the Web Runtime to discover the location (latitude and longitude) of the device.

Article Metadata
Code ExampleCompatibility
Platform(s): S60 5th Edition
Keywords: device.getServiceObject(), Service.Location
Created: tapla (23 Oct 2008)
Last edited: hamishwillee (04 Oct 2012)


Source: script.js

var serviceObj = null;
window.onload = init;
// Initializes the widget
function init() {
// Obtain the Location service object
try {
serviceObj = device.getServiceObject("Service.Location", "ILocation");
} catch (ex) {
alert("Service object cannot be found.");
// We are interested in basic location information (longitude, latitude
// and altitude) only, so let's define the criteria respectively
var criteria = new Object();
criteria.LocationInformationClass = "BasicLocationInformation";
// Obtain the location information (synchronous)
var result = serviceObj.ILocation.GetLocation(criteria);
var latitude = result.ReturnValue.Latitude;
var longitude = result.ReturnValue.Longitude;
// Display the location
alert("Lat. " + latitude + ", Long. " + longitude);

Note: GetLocation() is a synchronous function, so it may block your widget for a while.


The current location (latitude and longitude) of the device is displayed.

Supplementary material

See also

This page was last modified on 4 October 2012, at 05:28.
33 page views in the last 30 days.