Address on the Spot: Using Google’s Reverse Geocoding API

Google just launched a new feature as part of its geolocation services: a Reverse Geocoding feature as part of the Google Maps API.

The API is really simple to use. It took me only a few hours to put together a quick little utility called Address on the Spot, which allows you to double click anywhere on a map to find an address for a location.

So here’s a quick how to for using the Reverse Geocoding API.

First, create a GLatLng object with a set of geocoordinates:

point = new GLatLng(45.523875, -122.670399);

Next, create a GClientGeocoder object and pass the point object to it, along with a callback function. The callback function display_address() will be executed when the geocoder returns a response.

geocoder = new GClientGeocoder();
geocoder.getLocations(point, display_address);

Here’s what display_address() might look like:

function display_address(response) {
    var address;
    if (!response || response.Status.code != 200) {
        address = "No location data found."
    } else {
        address = response.Placemark[0].address;
    }
    alert(address);
}

Couldn’t be easier. It’s definitely a handy addition to the Google Maps API, and this utility was pretty fun and easy to build.

Post a comment

Contact Info
will not be published

include http://

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>