| ID | CS001161 | Creation date | October 30, 2008 |
| Platform | S60 5th Edition | Tested on devices | |
| Category | Web Runtime (WRT) | Subcategory | S60 Platform Services |
| Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.Location |
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.
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.
The current location (latitude and longitude) of the device is displayed.