Monthly Archives: May 2011

You are browsing the site archives by month.

Extracting Latitude and Longitude Coordinates of an Address

It is 6 AM – I will be hitting the hay shortly after sunrise as I finish coding a new component for my CRM. Part of the system required me to geocode an address before storing it in the database. Geocoding refers to extracting the latitude and longitude coordinates of a specified location. During my research, I found some amazing open datasets to help build such a system. However, I eventually sided with using Google’s enormous database of geocoded locations because I assume it is the most up-to-date.

So I ended up coding the following PHP script to extract the lat and lng coordinates of addresses submitted by the user. The script uses jQuery to send an AJAX request for a JSON output after querying the XML API for Google Maps.

I know this script would be useful for others so I am making it available to everyone. To use this code in your own projects, simply change the Google Maps API key found on line 10.

Use the following link to Download the Full Code. Have fun!