Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Revision as of 05:28, 4 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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
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 05:28.
56 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.

×