Login     Sign Up
Tugadar (@admin)
21 days ago

Using Location - Based Services

Location-based services (LBS) is an umbrella term used to describe the different technologies used to find the device’s current location. The two main LBS elements are:

  • ❑LocationManager Provides hooks to the location-based services.
  • ❑LocationProviders Each of which represents a different location-finding technology used to determine the device’s current location.

Using the Location Manager, you can:

  1. ❑ Obtain your current location.
  2. ❑ Track movement.
  3. ❑Set proximity alerts for detecting movement into and out of a specified area.

Setting up the Emulator with Test Providers

Location-based services are dependant on device hardware for finding the current location. When developing and testing with the emulator, your hardware is virtualized, and you’re likely to stay in pretty much the same location.

To compensate, Android includes hooks that let you emulate Location Providers for testing location-based applications. In this section, you’ll learn how to mock the position of the supported GPS provider.

If you’re planning on doing location-based application development and using the Android emulator, this section will show how to create an environment that simu-lates real hardware and location changes. In the remainder of this chapter, it will be assumed that you have used the examples in this section to update the location for, the GPS_PROVIDER within the emulator.

Updating Locations in Emulator Location Providers

Use the Location Controls available from the DDMS perspective in Eclipse (shown in Figure 7-1) to push location changes directly into the test GPS_PROVIDER.

Figure 7-1 shows the Manual and KML tabs. Using the Manual tab, you can specify particular latitude/ longitude pairs. Alternatively, the KML and GPX tabs let you load KML (Keyhole Markup Language) and GPX (GPS Exchange Format) files, respectively. Once loaded, you can jump to particular waypoints (locations) or play back each location sequentially.

Most GPS systems record track files using GPX, while KML is used extensively online to define geographic information. You can handwrite your own KML file or generate one automatically using Google Earth and finding directions between two locations.

All location changes applied using the DDMS Location Controls will be applied to the GPS receiver, which must be enabled and active. Note that the GPS values returned by getLastKnownLocation will not change unless at least one application has requested location updates.