Maps Geocoding and Location Based Services

WHAT'S IN THIS CHAPTER?_

> Forward and reverse geocoding

> Creating interactive maps with Map Views and Map Activities

> Creating and adding Overlays to maps

> Finding your location with location-based services

> Using proximity alerts

One of the defining features of mobile phones is their portability, so it's not surprising that some of the most enticing Android features are the services that let you find, contextualize, and map physical locations.

You can create map-based Activities using Google Maps as a user interface element. You have full access to the map, which enables you to control display settings, alter the zoom level, and pan the display. Using Overlays you can annotate maps and handle user input to provide map-contextualized information and functionality.

Also covered in this chapter are the location-based services (LBS), the services that let you find the device's current location. They include technologies like GPS and Google's cell-based location technology. You can specify which location-sensing technology to use explicitly by name, or implicitly by defining a set of criteria in terms of accuracy, cost, and other requirements.

Maps and location-based services use latitude and longitude to pinpoint geographic locations, but your users are more likely to think in terms of an address. Android provides a Geocoder that supports forward and reverse geocoding. Using the Geocoder you can convert back and forth between latitude/longitude values and real-world addresses.

Used together, the mapping, geocoding, and location-based services provide a powerful toolkit for incorporating your phone's native mobility into your mobile applications.

Prepared for ASHLEE KABAT, email: [email protected] Order number: 56760408 This PDF is for the purchaser's personal use in accordance with the Wrox Terms of Service and under US copyright as stated on this book's copyright page. If you did not purchase this copy, please visit www.wrox.com to purchase your own copy.

USING LOCATION-BASED SERVICES

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

> Location Manager Provides hooks to the location-based services

> Location Providers Each of these represents a different location-finding technology used to determine the device's current location

Using the Location Manager, you can:

> Obtain your current location

> Track movement

> Set proximity alerts for detecting movement into and out of a specified area

> Find available Location Providers

CONFIGURING THE EMULATOR TO TEST LOCATION-BASED SERVICES

Location-based services are dependent on device hardware to find the current location. When you are 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 are using the Android Emulator, this section will show you how to create an environment that simulates real hardware and location changes. For 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, or that you are using a physical device.

UPDATING LOCATIONS IN EMULATOR LOCATION PROVIDERS

Use the Location Controls available from the DDMS perspective in Eclipse (shown in Figure 8-1) to push location changes directly into the emulator's GPS Location Provider.

Figure 8-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 these are loaded you can jump to particular waypoints (locations) or play back each location sequentially.

Prepared for ASHLEE KABAT, email: [email protected] Order number: 56760408 This PDF is for the purchaser's personal use in accordance with the Wrox Terms of Service and under US copyright as stated on this book's copyright page. If you did not purchase this copy, please visit www.wrox.com to purchase your own copy.

FIGURE 8-1

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 by using Google Earth to find 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.

SELECTING A LOCATION PROVIDER

Depending on the device, there may be several technologies that Android can use to determine the current location. Each technology, or Location Provider, will offer different capabilities, including differences in power consumption, monetary cost, accuracy, and the ability to determine altitude, speed, or heading information.

To get an instance of a specific provider, call getProvider, passing in the name:

String providerName = LocationManager.GPS_PROVIDER; LocationProvider gpsProvider;

gpsProvider = locationManager.getProvider(providerName);

This is generally useful only for determining the abilities of a particular provider. Most Location Manager methods require only a provider name to perform location-based services.

Prepared for ASHLEE KABAT, email: [email protected] Order number: 56760408 This PDF is for the purchaser's personal use in accordance with the Wrox Terms of Service and under US copyright as stated on this book's copyright page. If you did not purchase this copy, please visit www.wrox.com to purchase your own copy.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Responses

  • gilda
    How to test location based applications in amulater in android?
    7 years ago

Post a comment