Archived:Checking for S60 Platform Services support in Symbian Web Runtime
Article Metadata
Code Example
Tested with
Compatibility
Article
Contents |
Overview
Access to device resources from a WRT widget via S60 Platform Services is currently only supported in S60 5th Edition.
Here's the code for a simple widget, checking the existence of the JavaScript device object extension.
Preconditions
S60 3rd Edition FP2 or S60 5th Edition emulator is needed for testing.
Widget HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>My Location Aware Widget</title>
<script type="text/javascript">
window.onload = function() {
var serviceObject;
try{
serviceObject = device.getServiceObject("Service.Location", "ILocation");
}
catch(e){
if( e.name == 'ReferenceError' )
alert('device object cannot be found');
else
alert(e);
return;
}
try{
var criteria = new Object();
var result = serviceObject.ILocation.GetLocation(criteria);
var latitude = result.ReturnValue.Latitude;
var longitude = result.ReturnValue.Longitude;
alert('Latitude= ' + latitude + '\nLongitude= ' + longitude);
}
catch(e){
alert(e);
}
};
</script>
</head>
<body>
</body>
</html>
Postconditions
If the device object exists, the widget pops up an alert box with the latitude and longitude acquired from the active positioning system on the device.
Otherwise an alert box with the text 'device object cannot be found' is shown to the user.
Please note that the GetLocation call used in this example is synchronous and may block your widget for a while, depending on the used positioning system. Check out the WRT Developer's Library for an example on calling the asynchronous version of the function.
You might want to install the simulation PSY to your device to remove the dependency to the availability of real positioning data.
Test application and other attachments (optional)
Please rename the .zip file to .wgz before attempting to install it on the emulator or a real device.

