Google Geocoding Service – get latitude, longitude from address, postcode


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:

  • q = address that you are searching for, it can be anything from a postcode to any full or partial address. Google will search the best matching result for you.
  • output = this is the output format of the response. Can be json, xml, kml or csv. Isn’t it great?
  • oe = output encoding format. This is optional but strongly encouraged.
  • sensor = value can be either true or false. This indicates that whether the request is coming from any device with location sensor.
  • key = your google api key
  • 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. #1 by Ryan McDermott on July 25, 2009 - 9:27 pm

      Great script, I\’ve been looking for this! can you plz send me it?

      thanks!

    2. #2 by Imran on July 25, 2009 - 10:51 pm

      Hi Ryan, Sent to your email address. Thanks a lot for coming.

    3. #3 by steve on August 7, 2009 - 8:51 pm

      thats just what ive been looking could you please send me the script?

    4. #4 by Imran on August 7, 2009 - 8:59 pm

      Hi Steve,
      Sent it to your email. Thanks for coming.

    5. #5 by Ray on May 2, 2010 - 4:57 pm

      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. #6 by Imran on May 2, 2010 - 5:13 pm

      Sent to your email address. Keep coming :-)

    7. #7 by Kaspar on May 5, 2010 - 9:17 pm

      Hello, very good stuff! Is it possible to get the script? Appreciated.

    8. #8 by Imran on May 6, 2010 - 1:26 pm

      Hi Kaspar, Sent the script to your email address. Keep coming.

    9. #9 by Allan G on May 12, 2010 - 6:17 pm

      Just awesome, simply awesome. Any chance of a look at that script?

    10. #10 by Imran on May 12, 2010 - 8:11 pm

      Hi Allan,
      On the way to your mail account. Thanks :-)

    11. #11 by Sam on May 22, 2010 - 11:11 pm

      Good stuff!

      Any chance I can have the script?

      Thx, Sam

    12. #12 by Imran on May 24, 2010 - 2:09 pm

      Hi Sam,

      Sent to your email address. Thanks for coming.

    13. #13 by Jay on June 11, 2010 - 4:00 pm

      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. #14 by Imran on June 11, 2010 - 5:10 pm

      Hi Jay,

      Sent to your mail add. Yes you need your own API key.

      Cheers

    15. #15 by Jay on June 11, 2010 - 6:32 pm

      Hi,

      I have figure it our, but it is not showing the longitude and latatude values?

      any ideas

    16. #16 by Imran on June 11, 2010 - 6:56 pm

      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.

    17. #17 by dave on October 10, 2010 - 5:59 pm

      hey great work. could i please see how this script works?

      thanks!

    18. #18 by Glen on November 1, 2010 - 6:33 pm

      Hi, this is great. I’d love to have a look at your script, please! Thanks for this good work!
      G

    19. #19 by sachin on November 5, 2010 - 12:53 am

      Hi. please can you send this amazing script. it will be of great help

    20. #20 by James on November 9, 2010 - 1:00 am

      This is cool — any chance you could email it to me too?! Thanks!!! Going to use this for a school project!!!

    21. #21 by Dave on December 4, 2010 - 5:05 am

      Imran, nice work. Could I get the script too please?

    22. #22 by vijay on January 10, 2011 - 1:47 pm

      Nice script dude,

      could you please send this script to me as i also want to see how this great code run.

      Thanks

    23. #23 by Sundar on January 12, 2011 - 10:13 pm

      Hi Imran – Could you send me the script. It seems awesome!

    24. #24 by Frederick Ahmed on February 21, 2011 - 2:01 am

      Hi Imran,

      This is awesome, just what I have been looking for. Could you pleeze, most kindly send me the php script.

      Best regards
      Frederick

    25. #25 by Frederick Ahmed on February 21, 2011 - 2:04 am

      Hi Imran,

      This is awesome, just what I have been looking for. Could you pleeze send me the php script.

      Best regards
      Frederick

    26. #26 by Chandan Sinha on February 23, 2011 - 7:06 pm

      Send me the script, please…

    27. #27 by vlad on March 7, 2011 - 8:22 am

      Hello
      i was looking for something like that! could you send me the script please

    28. #28 by florin on March 29, 2011 - 6:46 pm

      Hello
      Great script
      could you send me the script please?

    29. #29 by Michael Plant on March 30, 2011 - 12:04 pm

      Brilliant.Been searching the web for info on geocoding. Can you send me the script please?

    30. #30 by Mark Bagnall on April 9, 2011 - 3:36 am

      Great script, will definitely be a great help, any chance you could email me a copy

    31. #31 by Alok on April 28, 2011 - 12:26 pm

      Hi
      I was also looking for something like that! could you please send me the script ASAP.

      Thanks in Advance !!!

    32. #32 by John Smith on July 22, 2011 - 6:17 am

      Can you send me this script please – it looks great

    33. #33 by Mark Bagnall on August 12, 2011 - 3:07 am

      Got the script working, it is awesome, any idea how I would get the pointer on there to give the exact location?

    34. #34 by Dave on August 15, 2011 - 8:06 pm

      Hi
      A big help, Im trying to learn about teh google API, could you send the script for me to have a look through?

      Tnaks Dave

    35. #35 by rob on November 25, 2011 - 7:47 am

      Hello,

      I like your work.

      Could you please send me your script?

      Thanks again

      Kind Regards,
      Rob

    36. #36 by rob on November 25, 2011 - 7:48 am

      Hello,

      I like your work.

      I would be greateful if you could please send me your script?

      Thanks again

      Kind Regards,
      Rob

    37. #37 by rob on November 25, 2011 - 7:48 am

      Hello,

      I like your work.

      I would be greateful if you could please send me your script? thanks

      Thanks again

      Kind Regards,
      Rob

    38. #38 by bhumika on December 26, 2011 - 11:05 am

      Hi,

      Really good stuff. I would like to learn more in Google Geocoding Api.can you please send me your script?

      Regards,
      Bhumi

    39. #39 by stu mackin on January 14, 2012 - 1:27 am

      Hi Mate, can you email me the script?

      Cheers

    40. #40 by sully on June 13, 2012 - 3:07 am

      HI,

      Please email me this script, its very good, thanks

    41. #41 by Jeff on June 22, 2012 - 9:01 pm

      LOVE THE SCRIPT! Can you send me a copy and can I use it on my own site?

    42. #42 by richard on July 16, 2012 - 4:37 am

      Been looking for this script, would appriciate it if you could send me a copy please.

    43. #43 by Jeffstah on July 20, 2012 - 2:46 pm

      Hey, great script, was looking exactly for this in PHP! I’d really like to have a copy if I may? Thanks in advance!

    44. #44 by Konrad on August 3, 2012 - 6:18 pm

      Hi Imran,

      If you could please send me the code. Many thanks in advance,

      Konrad

    45. #45 by Joe on August 17, 2012 - 2:53 am

      Hi Imran,

      Could you please send me the code? Thank you!

      Joe

    46. #46 by bina patel on August 23, 2012 - 4:09 am

      Great script, I have been looking for this! can you plz send me it? my email id is patel_she9@yahoo.co.in
      please send me as soon as possible

      thanks!

    47. #47 by sumit on August 29, 2012 - 2:37 pm

      hello ,
      please i want google map address to get Postcode please help me example UK post code

    48. #48 by Andy Kirke on September 27, 2012 - 3:01 am

      Please Imran, may i have the script…..Thanks

    49. #49 by Rajharajesuwari on October 30, 2012 - 11:11 am

      can u please send me the php script

    50. #50 by Samuel Gertler on November 11, 2012 - 8:36 am

      Same here, where could I find the script for this?

    Comments are closed.