org.symbian.tools.wrttools.doc.WebDeveloper/html/GUID-4DDE31C7-EC0D-4EEC-BC3A-A0B0351154F8.html
author Eugene Ostroukhov <eugeneo@symbian.org>
Fri, 04 Jun 2010 09:44:40 -0700
changeset 345 7723a46fe224
parent 229 716254ccbcc0
permissions -rw-r--r--
Bug 2480 - Excluded resources are still available in preview and debugger


<!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" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="copyright" content="(C) Copyright 2009"/><meta name="DC.rights.owner" content="(C) Copyright 2009"/><meta name="DC.Type" content="mobileconcept"/><meta name="DC.Title" content="Accessing device location information"/><meta name="DC.Relation" scheme="URI" content="GUID-CF55DBA3-2D4C-4FD0-8A06-862E6128F4E7"/><meta name="DC.Relation" scheme="URI" content="GUID-D581028C-06ED-422D-866E-AE6C93075084"/><meta name="DC.Relation" scheme="URI" content="GUID-1EFD7043-E9B8-4B4E-9EA6-A20B3EECC14A"/><meta name="DC.Relation" scheme="URI" content="GUID-46EABDC1-37CB-412A-ACAD-1A1A9466BB68"/><meta name="DC.Format" content="XHTML"/><meta name="DC.Identifier" content="GUID-4DDE31C7-EC0D-4EEC-BC3A-A0B0351154F8"/><title>Accessing
device location information </title><script type="text/javascript">
      function initPage() {}
    </script><link href="../PRODUCT_PLUGIN/book.css" rel="stylesheet" type="text/css"/><link href="css/s60/style.css" rel="stylesheet" type="text/css" media="all"/></head><body onload="initPage();"><div class="body"><div class="contentLeft prTxt"><h1 class="pageHeading" id="GUID-4DDE31C7-EC0D-4EEC-BC3A-A0B0351154F8">Accessing
device location information</h1><div>
<p>The <a href="GUID-53CE4DE6-F065-4339-8C18-5C30A9540053.html#GUID-53CE4DE6-F065-4339-8C18-5C30A9540053">Location
Service API</a> allows <span>widgets</span> to retrieve information about
the physical location of a device and to perform calculations based on location
information. You can use the Location Service to create <span>widgets</span> that
provide location-based services (LBS). For example, you can create <span>widgets</span> that:</p>
<ul>
<li><p>Provide directions to a destination, for example the nearest
restaurant</p></li>
<li><p>Monitor the locations of snow-plowing vehicles</p></li>
<li><p>Calculate distances between geographical locations</p>
</li>
</ul>
<p>The Location Service relies on the GPS capabilities of the device to
provide location information. If the device does not include or is not connected
to a positioning system, the service cannot provide such information.</p>
<div><h3>Accessing the API and supported methods</h3>
<p>To create a <a href="GUID-04095E9A-50E7-4E5F-BD6F-71DA281A0080.html#GUID-04095E9A-50E7-4E5F-BD6F-71DA281A0080">service
object</a> for the Location Service API, use <code>Service.Location</code> to
identify the service provider and <code>ILocation</code> to identify
the supported interface:</p>

<pre class="codeblock" id="GUID-AB3999E2-E092-4AD6-A1B3-B601877521F6">var so = device.getServiceObject("Service.Location", "ILocation");</pre>
<p>The <code>ILocation</code> interface provides the following
methods:</p>
<ul>
<li><p><a href="GUID-150E440F-56E4-4249-8739-A5A7A2050600.html#GUID-150E440F-56E4-4249-8739-A5A7A2050600"><code>GetLocation()</code></a></p>

<p>Use the <code>GetLocation()</code> method to retrieve the current
location of the device.</p>

</li>
<li><p><a href="GUID-7A0190CB-545E-48D2-BAF0-D28E03CDFCA5.html#GUID-7A0190CB-545E-48D2-BAF0-D28E03CDFCA5"><code>Trace()</code></a></p>

<p>Use the <code>Trace()</code> method to retrieve periodic updates
about the current location of the device.</p>

</li>
<li><p><a href="GUID-DBEE8177-7246-4FEE-A0F1-D6AEEA6EA206.html#GUID-DBEE8177-7246-4FEE-A0F1-D6AEEA6EA206"><code>Calculate()</code></a></p>

<p>Use the <code>Calculate()</code> method to perform mathematical
calculations based on a source location and a target location.</p>

</li>
<li><p><a href="GUID-7A466B60-88DD-4A3A-B64C-E7300D42DA56.html#GUID-7A466B60-88DD-4A3A-B64C-E7300D42DA56"><code>CancelNotification()</code></a></p>

<p>Use the <code>CancelNotification()</code> method to cancel an
ongoing asynchronous call. This method is valid for any asynchronous call
made through the Location Service API.</p>

</li>
</ul>
</div>
<div><h3>Using the service in a widget</h3>
<p>To access location information using the Location Service API:</p>
<ol>
<li id="GUID-09408614-B079-437A-BF7C-1580105906C1-GENIDd0e8097"><a name="GUID-09408614-B079-437A-BF7C-1580105906C1-GENIDd0e8097"><!----></a><p>Create a service
object for the API using <a href="GUID-04095E9A-50E7-4E5F-BD6F-71DA281A0080.html#GUID-04095E9A-50E7-4E5F-BD6F-71DA281A0080"><code>device.getServiceObject()</code></a>.</p>
</li>
<li id="GUID-C7877560-C290-4E7D-980C-D65D50DC5B4A-GENIDd0e8106"><a name="GUID-C7877560-C290-4E7D-980C-D65D50DC5B4A-GENIDd0e8106"><!----></a><p>Define the
tasks you want to perform and choose the correct methods for them.</p>
</li>
<li id="GUID-C4DFB650-8BAD-4947-AE25-74DFCD52229C-GENIDd0e8111"><a name="GUID-C4DFB650-8BAD-4947-AE25-74DFCD52229C-GENIDd0e8111"><!----></a><p>Optionally,
define how you want the results filtered.</p></li>
<li id="GUID-03590B36-FFCA-4E39-A781-92080EE16B34-GENIDd0e8115"><a name="GUID-03590B36-FFCA-4E39-A781-92080EE16B34-GENIDd0e8115"><!----></a><p>Define methods
for processing the results.</p></li>
<li id="GUID-B7AF643B-5587-40D5-A423-0EAF4D3A8DFF-GENIDd0e8119"><a name="GUID-B7AF643B-5587-40D5-A423-0EAF4D3A8DFF-GENIDd0e8119"><!----></a><p>Retrieve the
location information using the methods defined in step 2. Use asynchronous
methods together with <a href="GUID-C7C3B541-8D28-4DC6-9003-ECF57F26C608.html#GUID-C7C3B541-8D28-4DC6-9003-ECF57F26C608"><code>callback()</code></a>.</p>
</li>
<li id="GUID-76B47850-874B-4F80-9440-DB7E2A2B9477-GENIDd0e8128"><a name="GUID-76B47850-874B-4F80-9440-DB7E2A2B9477-GENIDd0e8128"><!----></a><p>Process the
results with the methods defined in step 4.</p></li>
</ol>
<p>For the complete source of a sample widget that demonstrates how to
use this service, see <a href="GUID-620340F8-F844-445E-80AA-71C757320B7E.html#GUID-620340F8-F844-445E-80AA-71C757320B7E">the full example</a>.</p>
</div>
</div></div></div><div class="footer"><hr/><div class="copy">© Nokia 2009.</div></div></body></html>