×
Namespaces

Variants
Actions
(Difference between revisions)

Tracking changes in the current location in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot fixing redirect link)
hamishwillee (Talk | contribs)
m (Hamishwillee -)
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian Web Runtime]][[Category:S60 Platform Services]][[Category:Location]][[Category:Code Snippet]][[Category:S60 5th Edition]]
__NOEDITSECTION__
+
{{Abstract|This code snippet demonstrates how to track changes in the current location on Symbian Web Runtime, using the Location Service API.}}
{{KBCS}}
+
 
{{CodeSnippet
+
{{ArticleMetaData <!-- v1.2 -->
|id=CS001176
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|platform=S60 5th Edition
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices=Nokia 5800 XpressMusic
+
|devices= Nokia 5800 XpressMusic
|category=Web Runtime (WRT)
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|subcategory=S60 Platform Services
+
|platform= S60 5th Edition
|creationdate=November 17, 2008
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|keywords=device.getServiceObject(), Service.Location, Service.Location.Trace()
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= device.getServiceObject(), Service.Location, Service.Location.Trace()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20081117
 +
|author= [[User:Nokia Developer KB]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001176
 
}}
 
}}
 
==Overview==
 
 
This code snippet demonstrates how to track changes in the current location by using the Location Service API of the Web Runtime (WRT).
 
  
 
==Source: widget.xhtml==
 
==Source: widget.xhtml==
Line 122: Line 133:
 
==See also==
 
==See also==
  
* [[CS001177 - Cancelling an asynchronous function call]]
+
* [[Cancelling an asynchronous function call in Symbian Web Runtime]]
 
* [http://www.developer.nokia.com/Resources/Library/Web/ Web Developer's Library: JavaScript Location Service API]
 
* [http://www.developer.nokia.com/Resources/Library/Web/ Web Developer's Library: JavaScript Location Service API]
 
[[Category:Symbian Web Runtime]][[Category:S60 Platform Services]][[Category:Code Snippet]]
 

Latest revision as of 09:38, 5 October 2012

This code snippet demonstrates how to track changes in the current location on Symbian Web Runtime, using the Location Service API.

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.Location, Service.Location.Trace()
Created: User:Nokia Developer KB (17 Nov 2008)
Last edited: hamishwillee (05 Oct 2012)

Contents

[edit] Source: widget.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="StyleSheet" href="style/general.css" type="text/css" />
<script type="text/javascript" src="script/script.js" />
<title>WRT Application</title>
</head>
<body>
<div id="bodyContent" class="bodyContent">
<div id="location">
<table id="locationData">
<tr id="latitude">
<td id="latitudeHeading">Lat.</td>
<td id="latitudeData"></td>
</tr>
<tr id="longitude">
<td id="longitudeHeading">Long.</td>
<td id="longitudeData"></td>
</tr>
</table>
</div>
<input type="button" value="Start tracking"
onclick="startTracking();" />
</div>
</body>
</html>

[edit] Source: script.js

var serviceObj = null;
var criteria = 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;
}
 
// Initialize the criteria for the service object
criteria = new Object();
criteria.LocationInformationClass = "BasicLocationInformation";
}
 
// Starts the tracking
function startTracking() {
if (serviceObj == null) {
alert("Service object has not been initialized.");
return;
}
 
try {
// Define the callback function for tracking the location
var result = serviceObj.ILocation.Trace(criteria, locationDataReady);
} catch (ex) {
alert(ex);
}
}
 
// Called when Trace has got data
function locationDataReady(transId, eventCode, result) {
// On error situation, display the error message
if (eventCode == 4) {
alert("Error " + result.ErrorCode + ": " + result.ErrorMessage);
return;
}
 
var latitude = result.ReturnValue.Latitude;
displayData("latitudeData", latitude.toFixed(4) + " \u00B0");
 
var longitude = result.ReturnValue.Longitude;
displayData("longitudeData", longitude.toFixed(4) + " \u00B0");
}
 
// Displays the data in an HTML element
function displayData(elementId, data) {
var element = document.getElementById(elementId);
 
// Remove the first child node, if it's not null
if (element.firstChild != null) {
element.removeChild(element.firstChild);
}
 
element.appendChild(document.createTextNode(data));
}

[edit] Postconditions

The changes in current location are displayed.

[edit] See also

This page was last modified on 5 October 2012, at 09:38.
54 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.

×