Google has a very handy web service available for geocoding. Very often we require to know the longitude, latitude of a postcode, may be for finding distance between 2 places or any other reasons (who cares) and as always, Google is ready with the service before you realize you’ll need that
. This is the beauty of google – they thinks ahead.
To use the service, at first, you need to get a google api key for your site which takes less than 30 seconds from here.
Following is the typical format of the request string to get geocoding information:
http://maps.google.com/maps/geo?q=95678&output=json&oe=utf8&sensor=false&key=your_key_here
Description:
There are lot other options to be added. You can find official documentation here
Following is a simple geocoding script I wrote in PHP to get the lat/long of a postcode (it can be any address format other than postcode). Ask me in comments if you want the script, I’ll mail it to you.
Open the app in new window


#1 by Ryan McDermott on July 25th, 2009
Great script, I\’ve been looking for this! can you plz send me it?
thanks!
#2 by Imran on July 25th, 2009
Hi Ryan, Sent to your email address. Thanks a lot for coming.
#3 by steve on August 7th, 2009
thats just what ive been looking could you please send me the script?
#4 by Imran on August 7th, 2009
Hi Steve,
Sent it to your email. Thanks for coming.
#5 by Ray on May 2nd, 2010
I see that this was last year, but appears to be what I am looking for. Could you please send me the script.
Thanks
#6 by Imran on May 2nd, 2010
Sent to your email address. Keep coming
#7 by Kaspar on May 5th, 2010
Hello, very good stuff! Is it possible to get the script? Appreciated.
#8 by Imran on May 6th, 2010
Hi Kaspar, Sent the script to your email address. Keep coming.
#9 by Allan G on May 12th, 2010
Just awesome, simply awesome. Any chance of a look at that script?
#10 by Imran on May 12th, 2010
Hi Allan,
On the way to your mail account. Thanks
#11 by Sam on May 22nd, 2010
Good stuff!
Any chance I can have the script?
Thx, Sam
#12 by Imran on May 24th, 2010
Hi Sam,
Sent to your email address. Thanks for coming.
#13 by Jay on June 11th, 2010
Hello mate,
Could you please send me the script as I would like to use it for my forum members. The site is designed in joomla.
Will I need to get my own google API Keys?
cheers
#14 by Imran on June 11th, 2010
Hi Jay,
Sent to your mail add. Yes you need your own API key.
Cheers
#15 by Jay on June 11th, 2010
Hi,
I have figure it our, but it is not showing the longitude and latatude values?
any ideas
#16 by Imran on June 11th, 2010
Jay,
What I would suggest is:
1. Check if the script has any php error. Accidentally you might have added some characters(?)
2. Add “print_r($googleresponse)” at line 20 to see if googles response is coming through.