Google Address Translation
This is a hack that brings the power of address translation (converting a US Postal Address into a Latitude/Longitude) to the Google Maps API - something that wasn't provided in the default distribution.

View the Demo! - Download the Code
This hack, which is completely reusable, is broken down into a couple portions.
Address Translation Proxy (written in Perl)
This portion of this project queries the open API provided by Geocoder, which offers free address translation for any postal address in the United States. (If you live in Canada, you may want to check out Geocoder.ca). The code is very very simple, the only reason why it's needed is due to the fact that Javascript applications can't make queries to services that aren't on the same domain. The code is so short, I can show it here:
The above code does the following:
Javascript Addressing Querying
This simple function, written in Javascript, makes a query to the Address Translation Proxy asking it to convert an address into a Google GPoint. This function has two parameters that need to be taken into consideration:
The first argument, address, is a string representing the address that you want to translate (for example, "123 Main St. Anywhere, NY"). The second argument, callback, is a reference to a function which will be called once the translation is complete. That function will be called with two arguments:
The first argument, point, will either be a GPoint representing the latitude/longitude of an address OR null, if the address does not exist. The second argument is the same address as what was sent when you called GAddress.
Now, using both of these components, it's time to wrap them together and put them to use! If you're interested to see what a final result looks like, check out this demo.
If you'd like to put this code to use, feel free to download the code below and give it a try!
Download
- gaddress.tar.gz - Contains sample index.html, Javascript Query Function (gaddress.js), and Address Translation Proxy (gaddress.cgi). To install:
- Copy the contents of the archive to your web directory.
- Run the following command, from the command-line (or your favorite FTP client) chmod 0755 gaddress.cgi
- Go to the Google Maps API signup page and generate an API key for the URL where you uploaded the files.
- Finally, get the API key which you generated, open index.html, and change key=CHANGEME to represent your API key.
- You should be good to go! Have fun!
Tags: hacks, google, perl, popular, address, maps, geocoder, geo
78 Comments on 'Google Address Translation'



