Good UX Means Good Business
In a world where technology is rapidly advancing and user expectations are rising, it’s no longer enough to have an average user experience; to delight your users and surpass your competition you must strive for the exceptional.
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.
and here’s the workflow:
- Generate a hard-coded LatLng pair
- Display it on the map with marker A
- Send the coordinates to the reverse geocoding service
- Extract the formatted address and converted LatLng pair from the GeocoderResults object
- 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.