×
Namespaces

Variants
Actions

Obtaining location information using Symbian Web Runtime

From Nokia Developer 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
Article
Keywords: device.getServiceObject(), Service.Location
Created: tapla (23 Oct 2008)
Last edited: hamishwillee (04 Oct 2012)

Contents

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.");
return;
}
 
// 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.

Postconditions

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 08:28.
75 page views in the last 30 days.
×