You Are Here:

Community: Wiki

This page was last modified on 15 October 2009, at 13:35.

Acquiring a cached location value in WRT

From Forum Nokia Wiki



ID   Creation date October 15th, 2009
Platform S60 5th Edition, S60 3rd FP2 Tested on devices Nokia N97, Nokia N97 Mini
Category Web Runtime (WRT) Subcategory Platform Services


Keywords (APIs, classes, methods, functions): location javascript

Overview

Latest S60 devices incorporate a small but valuable addition to JavaScript Location Service API.

"Last known position" information is useful for getting a quick response from the location API on where the last positioning fix was acquired.

As a developer, you might want to first check if this cached value is available and ask the user if he's happy with the estimate, before requesting a new location fix from the framework.

I put together some sample code to assist you in integrating this feature to your widget.

The beef

Set up the location service object and call:

var result = locAPI.ILocation.GetLastPosition();

If the returned error code is 0, you can use the freshly acquired cached location data:

if (result.ErrorCode == 0){
var posObject = result.ReturnValue;
myLogger(posObject.Latitude + ' - ' + posObject.Longitude);
}

If the "last known position" feature is supported, but no cached data is available:

else if (result.ErrorCode == 1014){
myLogger('Last known position data is not available');
}

...and finally, if your user is sporting old SW, that does not support this feature

else{
myLogger('ErrorCode: ' + result.ErrorCode + '<br/>' + 'ErrorMessage: ' + result.ErrorMessage);
}

Devices that currently incorporate this feature

N97 20.0.019 and later N97 Mini 10.0.020 and later

Full example code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Sample Widget</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="javascript" type="text/javascript" src="basic.js"></script>
<link rel="stylesheet" href="basic.css" type="text/css">
<META NAME="Generator" CONTENT="Nokia WRT plug-in for Aptana Studio 2.2.0" />
 
<script>
var locAPI = null;
function init(){
locAPI = device.getServiceObject("Service.Location", "ILocation");
}
 
function getLastKnownPosition(){
 
if(!locAPI)
init();
 
// Here's the fancy (but hidden) API call
var result = locAPI.ILocation.GetLastPosition();
 
// Yey, we can use the cached location info!
if (result.ErrorCode == 0){
var posObject = result.ReturnValue;
myLogger(posObject.Latitude + ' - ' + posObject.Longitude);
}
 
// Last known position data is not available
else if (result.ErrorCode == 1014){
myLogger('Last known position data is not available');
}
 
// Hmpf, this SW version does not support last known position API
else{
myLogger('ErrorCode: ' + result.ErrorCode + '<br/>' + 'ErrorMessage: ' + result.ErrorMessage);
}
}
 
function myLogger(txt){
document.getElementById("myconsole").innerHTML = txt;
}
 
</script>
 
</head>
<body onload="init();">
<div><a style="font-size:1.5em" id="actionjackson" href="#" onclick="getLastKnownPosition();">Last known position</a></div>
<div id="myconsole"></div>
</body>
</html>

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fFileE3aMicrokernelE5fArchitectureE2eGIFX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ