1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

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

    Bookmark and Share

    ,

    1. #1 by Ryan McDermott on July 25th, 2009

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

      thanks!

    2. #2 by Imran on July 25th, 2009

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

    3. #3 by steve on August 7th, 2009

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

    4. #4 by Imran on August 7th, 2009

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

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

      Sent to your email address. Keep coming :-)

    7. #7 by Kaspar on May 5th, 2010

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

    8. #8 by Imran on May 6th, 2010

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

    9. #9 by Allan G on May 12th, 2010

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

    10. #10 by Imran on May 12th, 2010

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

    11. #11 by Sam on May 22nd, 2010

      Good stuff!

      Any chance I can have the script?

      Thx, Sam

    12. #12 by Imran on May 24th, 2010

      Hi Sam,

      Sent to your email address. Thanks for coming.

    13. #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. #14 by Imran on June 11th, 2010

      Hi Jay,

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

      Cheers

    15. #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. #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.

    17. #17 by dave on October 10th, 2010

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

      thanks!

    18. #18 by Glen on November 1st, 2010

      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 5th, 2010

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

    20. #20 by James on November 9th, 2010

      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 4th, 2010

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

    22. #22 by vijay on January 10th, 2011

      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 12th, 2011

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

    24. #24 by Frederick Ahmed on February 21st, 2011

      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 21st, 2011

      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 23rd, 2011

      Send me the script, please…

    27. #27 by vlad on March 7th, 2011

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

    28. #28 by florin on March 29th, 2011

      Hello
      Great script
      could you send me the script please?

    29. #29 by Michael Plant on March 30th, 2011

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

    30. #30 by Mark Bagnall on April 9th, 2011

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

    31. #31 by Alok on April 28th, 2011

      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 22nd, 2011

      Can you send me this script please – it looks great

    33. #33 by Mark Bagnall on August 12th, 2011

      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 15th, 2011

      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 25th, 2011

      Hello,

      I like your work.

      Could you please send me your script?

      Thanks again

      Kind Regards,
      Rob

    36. #36 by rob on November 25th, 2011

      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 25th, 2011

      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 26th, 2011

      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 14th, 2012

      Hi Mate, can you email me the script?

      Cheers

    (will not be published)
    Security Code:

    1. No trackbacks yet.