Reverse Geocoding

Reverse geocoding returns street addresses for physical locations, specified by latitude/longitude pairs. It provides a recognizable context for the locations returned by location-based services.

To perform a reverse lookup, you pass the target latitude and longitude to a Geocoder's getFromLocation method. It will return a list of possible matching addresses. If the Geocoder could not resolve any addresses for the specified coordinate, it will return null.

Listing 8-4 shows how to reverse-geocode your last known location.

LISTING 8-4: Reverse-geocoding your last known location Available for download on location =

Wrox.com locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER) ;

double latitude = location.getLatitude(); double longitude = location.getLongitude(); List<Address> addresses = null;

Geocoder gc = new Geocoder(this, Locale.getDefault()); try {

addresses = gc.getFromLocation(latitude, longitude, 10); } catch (IOException e) {}

The accuracy and granularity of reverse lookups are entirely dependent on the quality of data in the geocoding database; as a result, the quality of the results may vary widely between different countries and locales.

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


Post a comment