Petar Strinic

and all those sorts of things…

I was looking for a quick way to copy and paste an address and get its longitude and latitude, so obviously I looked to Google maps for the answer.
If you have a Google map instantiated you can use it to geocode of an address, with the GClientGeocoder class, but what if you don’t want a map at all?
Of course there is an HTTP API to do it, which seemed a bit more like what I needed.
Here’s a pretty simple class that will make an AJAX request to the Google Geocode API and return the address and longitude and latitude in a standard object, rather than the hierarchical mess that the API itself returns.

As you should have noticed, it uses the jQuery javascript framework. The key piece of information in the class above is dataType: ‘jsonp’ which allows you to get JSON data from another domain, without violating the same domain origin policy.
Below is a simple usage example of the GoogleGeocode class.

Download: GoogleGeocode.js


March 20th, 2009

Posted In: Misc

Tags: , , , ,