Enabling Location Testing on the Emulator

Many LBS features are available to developers without the special Google developer accounts and API keys. For example, you need a special API key to use Google Maps within an application, but you do not need any special permission to launch an Intent object to view a location that can be matched to any Map applications on the device.

Creating an AVD with Google APIs and Applications

You may have noticed that the basic Android installation (the target platform chosen when creating an AVD for use with the emulator) does not include the Maps application. To use the Android Maps application (developed by Google) with the Emulator, you need to create an Android AVD with the Google APIs target platform. Because you want to add some mapping features to the Been There, Done That! application, you need to create a new AVD for this target platform.

Configuring the Location of the Emulator

Unfortunately, the Android emulator just pretends to be a real device—that is, it doesn't actually have any hardware internals, so it cannot, for example, determine its current location via satellites. Instead, you have to seed the location information to the specific emulator instance. The easiest way to configure your emulator is to use the DDMS perspective in Eclipse. You need the latitude and longitude of the location you want the emulator to use.

Did you Know?

You can use Google Maps to determine GPS coordinates. To find a specific set of coordinates, go to http://maps.google.com and navigate to the location you desire. Center the map on the location by right-clicking the map and then choose the option to link to the map (usually in the top right corner of the screen, above the map). Copy the link URL—which has the GPS coordinates as part of the query string—to a text file. Find the last ll query variable, which should represent the latitude and longitude of the location. For example, the west edge of Yellowstone Lake in Yellowstone National Park has the ll value 44.427896,-110.585632. The ll value 44.427896,-110.585632 stands for latitude 44.427896 and longitude -110.585632. You can double-check these coordinates by pasting them into Google Maps again and seeing if the map pinpoints the same place location again.

To seed the emulator with a latitude and longitude, follow these steps:

1. Launch the emulator. If you're running an application, click the Home button.

2. Launch the Maps application.

3. Click the Menu button.

4. Choose the My Location menu item (see Figure 14.7).

FIGURE 14.7

The Maps application in the Android emulator.

5. Open Eclipse and click on the DDMS perspective.

6. Choose the emulator instance you want to send a location fix to.

7. In the Emulator Control pane, scroll down to the location control.

8. Enter the longitude and latitude of your desired location. Try the coordinates for Yellowstone National Park: latitude 44.427896 and longitude -110.585632 (see Figure 14.8).

9. Click Send.

H Emulator Control

Location Controls Manual [epx | KML @ Décimal © Sexagesimal Longitude -110585632 Latitude 44.427896 |Send|

FIGURE 14.8

Setting the location of the emulator to Yellowstone National Park with DDMS.

Back in the emulator, you'll notice that the Google map is now showing the location you seeded. Your screen should now display your location as Yellowstone National Park, as shown in Figure 14.9.

6:35 PM

Bïrtijjmsiwwfl jfi^i^

3 J

ml

©

1 In

Setting the location of the emulator to Yellowstone National Park.

You can also use the emulator console command-line tool to send a location fix with the geo fix command.

Did you Know?

0 0

Post a comment