Manso Trick: Getting the latitude/longitude from an address

For a project soon to be born (I hope), I’ve been doing a quick research for a way to obtain the latitude and longitude from a geographical address. For example, to determine the latitude/longitude from a totally random address like “Emerson Street, Palo Alto, California”  BTW, Hi Mariano! Thanks for the stay in USA last year 😀

This is called geocoding and after spending half a second looking searching on internet I’ve found two simple REST APIs. Yahoo! and Google provide their own APIs and I’m sure a lot of companies out there make use of it, because of their accuracy.

If you want to use Yahoo! API you need to sign up so they give you some sort of appid and you can start making queries.

In the other hand, Google let’s you do this as easily as:

http://maps.googleapis.com/maps/api/geocode/json?address=Emerson+Street,+Palo+Alto,+california&sensor=false

This URL returns a JSON response which can be easily parsed in all languages (you can also ask for the XML, but I sort of hate XML so I prefer JSON).

Apart from returning the latitude and longitude, it also returns the formatted address, which can be great to normalize the address in your database, in case you need such thing. For example, for the query before, it says the formatted address is:

“Emerson St, Palo Alto, CA, USA”

On top of that, you should always read the Terms Of Service to make sure your app stays aligned with the fair use of the API, but that’s up to you.

Although more inacurate, another interesting project is GeoNames (see the URL below).

For more information:

Trackback URL

, , , , ,

Comments are closed.