Skip to main content

Experience Management

Reverse Geocoding… with a grain of salt

In this post (the first in a series about the Google Maps API), we will take a closer look at how the Geocoding class works with respect to a recent client need.  Their requirement was to generate a cluster of postal addresses surrounding a given central address, so I began with looking over the API reference to see what was available.
For starters, geocoding is the process of taking a street address and converting it into a latitude/longitude pair that your map application can display.  Now, let’s say you have a bucket of these geographic coordinates but no meaningful addresses that users can understand – what do you do? Enter reverse geocoding.
Although the Google Maps API offers this functionality, it warns that it’s “not an exact science” – but what does that mean? I built a small application to find the answers.  Below is a mashup of screenshots showing the various location types returned by the geocoding service.
all types
and here’s the workflow:

  1. Generate a hard-coded LatLng pair
  2. Display it on the map with marker A
  3. Send the coordinates to the reverse geocoding service
  4. Extract the formatted address and converted LatLng pair from the GeocoderResults object
  5. Display it on the map with marker B

Notice that you can’t blindly trust the formatted address because it can range from a street address with a precise geocode (ROOFTOP in green) to a buoy in the Inner Harbor translated as a general place of interest (GEOMETRIC_CENTER in yellow).  Let’s revisit the client example and review a possible solution:
An algorithm, with pure math, creates a square grid of evenly-spaced points with the origin as the center.  Next, it reverse geocodes all points and filters on precise street addresses (ROOFTOP types) since we don’t want just any location.  However, to ensure we have plenty of data to work with, we increase the density of points and freely scrap any that don’t meet the criteria.
So what did we learn? There is plenty of supplemental data available from the API, you just need to know what to look for. Always be sure to spot check the data you’re getting and assess your tolerance on a case-by-case basis.

Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Narbeh Yousefian

More from this Author

Follow Us