Namespaces
Variants
Actions

Obtaining location information using Symbian Web Runtime

Jump to: navigation, search
Article Metadata

Code Example
Tested with
Devices(s):  

Compatibility
Platform(s): S60 5th Edition

Article
Keywords: device.getServiceObject(), Service.Location
Created: tapla (23 Oct 2008)
Last edited: hamishwillee (10 May 2012)

Contents

Overview

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.

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

  • You can test the location obtaining features in action in a simple, executable application into which this code snippet has been patched. The application is available for download at: Media:WRTStub CS001161.zip
  • You can examine all the changes that are required to implement the above mentioned features in an application. The changes are provided in unified diff and color-coded diff formats: Media:CS001161 Obtaining location information.diff.zip
  • For general information on applying the patch, see Using Diffs.
  • For unpatched stub applications, see Example stub.

See also

Comments

(no comments yet)

This page was last modified on 10 May 2012, at 06:01.
106 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2012 All rights reserved