page.title=Location and Maps
@jd:body

<div id="qv-wrapper">
<div id="qv">

  <h2>Location and Maps quickview</h2>
  <ul>
    <li>Android provides a location framework that your application can use to determine the device's location and bearing and register for updates.</li>
    <li>A Google Maps external library is available that lets you display and manage Maps data.</li>
  </ul>
  <h2>In this document</h2>
  <ol>
    <li><a href="#location">Location Services</a></li>
    <li><a href="#maps">Google Maps External Library</a></li>
  </ol>
  <h2>See Also</h2>
  <ol>
    <li><a href="http://code.google.com/android/add-ons/google-apis/index.html">Google APIs add-on download&raquo;</a></li>
  </ol>
</div>
</div>

<p>Location- and maps-based applications and services are compelling for mobile device users. You can build these capabilities into your applications using the classes of the {@link android.location} package and the Google Maps external library. The sections below provide details. </p>

<h2 id="location">Location Services</h2>

<p>Android gives your applications access to the location services supported by
the device through the classes in the <code>android.location</code> package. The
central component of the location framework is the 
{@link android.location.LocationManager} system service, which provides an API to
determine location and bearing if the underlying device (if it supports location
capabilities). </p>

<p>As with other system services, you do not instantiate a LocationManager directly. 
Rather, you request an LocationManager instance from the system by calling 
{@link android.content.Context#getSystemService(String) getSystemService(Context.LOCATION_SERVICE)}. 
The method returns a handle to a new LocationManager instance.</p>

<p>Once your application has a handle to a LocationManager instance, your application 
will be able to do three things:</p>

<ul>
    <li>Query for the list of all LocationProviders known to the
    LocationManager for its last known location.</li>
    <li>Register/unregister for periodic updates of current location from a
    LocationProvider (specified either by Criteria or name).</li>
    <li>Register/unregister for a given Intent to be fired if the device comes
    within a given proximity (specified by radius in meters) of a given
    lat/long.</li>
</ul>

<p>However, during initial development in the emulator, you may not have access to real 
data from a real location provider (Network or GPS). In that case, it may be necessary to
spoof some data for your application using a mock location provider.</p>

<p class="note"><strong>Note:</strong> If you've used mock LocationProviders in
previous versions of the SDK, you can no longer provide canned LocationProviders
in the /system/etc/location directory. These directories will be wiped during boot-up.
Please follow the new procedures outlined below.</p>

<h3>Providing Mock Location Data</h3>

<p>When testing your application on the Android emulator, there are a couple different
ways to send it some mock location data: you can use the DDMS tool or the "geo" command 
option in the emulator console.</p>

<h4 id="ddms">Using DDMS</h4>
<p>With the DDMS tool, you can simulate location data a few different ways:</p>
<ul>
    <li>Manually send individual longitude/latitude coordinates to the device.</li>
    <li>Use a GPX file describing a route for playback to the device.</li>
    <li>Use a KML file describing individual placemarks for sequenced playback to the device.</li>
</ul>
<p>For more information on using DDMS to spoof location data, see the 
<a href="{@docRoot}guide/developing/tools/ddms.html#emulator-control">Using DDMS guide</a>.

<h4 id="geo">Using the "geo" command in the emulator console</h4>
<p>Launch your application in the Android emulator and open a terminal/console in
your SDK's <code>/tools</code> directory. Connect to the emulator console. Now you can use:</p>
<ul><li><code>geo fix</code> to send a fixed geo-location.
	<p>This command accepts a longitude and latitude in decimal degrees, and
	an optional altitude in meters. For example:</p>
	<pre>geo fix -121.45356 46.51119 4392</pre>
    </li>
    <li><code>geo nmea</code> to send an NMEA 0183 sentence.
	<p>This command accepts a single NMEA sentence of type '$GPGGA' (fix data) or '$GPRMC' (transit data).
	For example:</p>
	<pre>geo nmea $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62</pre>
    </li>
</ul>

<p>For information about how to connect to the emulator console, see 
<a href="{@docRoot}guide/developing/tools/emulator.html#console">Using the Emulator Console</a>.</p>

<h2 id="maps">Google Maps External Library</h2>

<p>To make it easier for you to add powerful mapping capabilities to your
application, Google provides a Maps external library that includes the
com.google.android.maps package. The classes of the com.google.android.maps
package offer built-in downloading, rendering, and caching of Maps tiles, as
well as a variety of display options and controls. </p>

<p>The key class in the Maps package is
<code>com.google.android.maps.MapView</code>, a subclass of 
{@link android.view.ViewGroup ViewGroup}. A MapView displays a map with data obtained
from the Google Maps service. When the MapView has focus, it will capture
keypresses and touch gestures to pan and zoom the map automatically, including
handling network requests for additional maps tiles. It also provides all of the
UI elements necessary for users to control the map. Your application can also
use MapView class methods to control the MapView programmatically and draw a
number of Overlay types on top of the map. </p>

<p>In general, the MapView class provides a wrapper around the Google Maps API
that lets your application manipulate Google Maps data through class methods,
and it lets you work with Maps data as you would other types of Views.</p>

<p>The Maps external library is not part of the standard Android library, so it
may not be present on some compliant Android-powered devices (although it is
likely to be present on most devices). Similarly, the Maps external library is
not included in the standard Android library provided in the SDK. So that you
can develop using the classes of the com.google.android.maps package, the Maps
external library is made available to you as part of the Google APIs add-on for
the Android SDK. </p>

<p>To learn more about the Maps external library and how to download and use the
Google APIs add-on, visit</p>

<p style="margin-left:2em;"><a
href="http://code.google.com/android/add-ons/google-apis">http://code.google.com/android/add-ons/google-apis</a></p>

<p>For your convenience, the Google APIs add-on is also included in the Android
SDK. <!-- To learn now to use the Maps external library in your application, see
[[Using External Libraries]].--></p>

<p class="note"><strong>Note:</strong> In order to display Google Maps data in a
MapView, you must register with the Google Maps service and obtain a Maps API
Key. For information about how to get a Maps API Key, see <a
href="http://code.google.com/android/add-ons/google-apis/mapkey.html">Obtaining
a Maps API Key</a>.</p>

