page.title=Location-based Service APIs @jd:body

The Android SDK includes two packages that provide Android's primary support for building location-based services: {@link android.location} and com.google.android.maps. Please read on below for a brief introduction to each package.

android.location

This package contains several classes related to location services in the Android platform. Most importantly, it introduces the {@link android.location.LocationManager} service, which provides an API to determine location and bearing if the underlying device (if it supports the service). The LocationManager should not be instantiated directly; rather, a handle to it should be retrieved via {@link android.content.Context#getSystemService(String) getSystemService(Context.LOCATION_SERVICE)}.

Once your application has a handle to the LocationManager, your application will be able to do three things:

However, during initial development, you may not have access to real data from a real location provider (Network or GPS). So it may be necessary to spoof some data for your application, with some mock location data.

Note: If you've used mock LocationProviders in previous versions of the SDK (m3/m5), 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 below.

Providing Mock Location Data

When testing your application on the Android emulator, there are a couple different ways to send it some spoof location data: with the DDMS tool or the "geo" command.

Using DDMS

With the DDMS tool, you can simulate location data a few different ways:

For more information on using DDMS to spoof location data, see the Using DDMS guide.

Using the "geo" command

Launch your application in the Android emulator and open a terminal/console in your SDK's /tools directory. Now you can use: