Caution

Just as Android-based cell phones are not required to include a camera, they are not required to include GPS hardware either, although many models likely will include both a camera and GPS hardware. Android included the Android Location-Based API in anticipation that GPS hardware will be included in many cell phones.

Because you are working on a software-based emulator, and not on a real device, the presence of GPS hardware has to be simulated. In this case, Android provides a file in the adb server that simulates having GPS hardware. The file is located at data/misc/location/<provider>

where <provider> represents the location information provider. The provider that Android supplies to you is data/misc/location/gps

Within the specific provider's folder could be any number of files that will hold the sample coordinates that you want Android to use. When you are using the Android Emulator, you can use the following types of files to store/retrieve GPS style coordinates. Each of these file types has a different format for providing information to the Android Location-Based API.

Let's take a look at what each of these files does and how they differ from each other.

A .kml file is a Keyhole Markup Language file. These files were originally developed for, and can be created by, Google Earth. The Android Location-Based API can parse a .kml file for coordinates to simulate a GPS.

data/misc/location/gps

To create a .kml file from Google Earth, open Google Earth and navigate to a location. In the following illustration, I have navigated to Tampa, Florida.

Choose File | Save As and choose KML. In the example, this produces a .kml file with the navigation information for Tampa, Florida. The following .kml code is from this file. Pay close attention to the <coordinates> tag, which is what the Android Location-Based API would be read in.

<?xml version="1.0" encoding="UTF-8"?>

<kml xmlns="http://earth.google.com/kml/2.2">

<Document>

<Styleid="default+icon=http://maps.google.com/mapfiles/kml/pal3/icon52.png"> <IconStyle>

<href>http://maps.google.com/mapfiles/kml/pal3/icon52.png</href> </Icon>

</IconStyle> <LabelStyle>

<scale>1.1</scale> </LabelStyle> </Style>

<Styleid="default+icon=http://maps.google.com/mapfiles/kml/pal3/icon6 0.png"> <IconStyle>

<href>http://maps.google.com/mapfiles/kml/pal3/icon6 0.png</href>

<StyleMapid="default+nicon=http://maps.google.com/mapfiles/kml/pal3/ icon6 0.png+hicon=http://maps.google.com/mapfiles/kml/pal3/icon52.png"> <Pair>

<key>normal</key> <styleUrl>#default+icon=http://maps.google.com/mapfiles/kml/pal3/ icon60.png</styleUrl> </Pair> <Pair>

<key>highlight</key> <styleUrl>#default+icon=http://maps.google.com/mapfiles/kml/pal3/ icon52.png</styleUrl> </Pair> </StyleMap> <Placemark>

<name>Tampa, FL</name> <open>1</open>

<address>Tampa, FL</address> <LookAt>

<longitude>-82.451142</longitude> <latitude>27.98146</latitude> <altitude>0</altitude> <range>38427.828125</range> <tilt>0</tilt> <heading>0</heading> </LookAt>

<styleUrl>#default+nicon=http://maps.google.com/mapfiles/kml/pal3/ icon6 0.png+hicon=http://maps.google.com/mapfiles/kml/pal3/icon52.png</styleUrl> <Point>

<coordinates>-82.451142,27.98146,0</coordinates> </Point>

</Placemark>

</Document>

You can create your own .kml files with Google Earth to simulate different locations. This is useful when you want to make an Activity that responds differently depending on the location of the user. The ease of creating .kml files makes this a very flexible alternative for simulating GPS hardware.

The file that Android provides in the gps folder is an .nmea file (National Marine Electronics Association file). An .nmea file can be output from many popular GPS products. These files are in a common format and can contain multiple coordinates and elevations, representing trips or tracks. The following sections discuss getting and opening this file in Windows and Linux, respectively.

The nmea file provided by Android represents a short trip through San Francisco.

Let's take a look inside the nmea file. Use the adb tool to pull the file from the server to your desktop:

adb pull <remote file> <local file>

The following illustration depicts the use of the adb pull command to retrieve the file.

G - \ftndro id\android-sdk_nS-rcl4_uindou^\android-sdk_nS-rcl4_uindous\tools>adh pu J * 1 data/misc/location/gps^nnea c:\flndroid

If your command executes successfully, you should see a message like that shown in the following illustration, indicating the size of the file downloaded.

E39 C:\Windows\system3Z\iiTid.exe1 _ jnj X

0 iNflndroidNaiidro id-sdJî_m5-rcl4_windowK\anriroid-sriJi_m5-rcl4_windows\t;oo ls>adb pul *

1 data/riisc-^locat j.on/gps^nmea c:\flndroi.d ?S4 ÏÎÏVî <5874V bytes i<? 9.ii76s>

C : \fln dro id\an dr o id -s dJi _nG -r c 14_w in do us \an dr o id -s dJi _mG -r cl 4_m in do if s \t o o Is >

Navigating to the C:\Android folder, you can see that the adb pull tool placed the nmea file here (see the following illustration).

0 0

Post a comment