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 Bas on December 1, 2012 - 5:15 am

      great script. can you please send it? thanks

    2. #2 by jay on December 10, 2012 - 9:58 am

      Hi Sounds great..

      Can you please email me the code..

      Thanks.

    3. #3 by jamie on December 10, 2012 - 8:56 pm

      What a great little script! if you could e-mail it over it would be much appreciated!

    4. #4 by pakaj on January 23, 2013 - 5:46 pm

      please send me script

    5. #5 by Vimal on February 4, 2013 - 10:05 pm

      Hello,

      One more simple example for get latlong of an address is described to following url:

      http://www.webslike.com/Thread-Geocoding-Example

    6. #6 by irfan on March 9, 2013 - 5:44 am

      Please can you send the email

    7. #7 by irfan on March 9, 2013 - 5:45 am

      Please can you email the script thanks

    8. #8 by alok on April 4, 2013 - 3:10 pm

      Greate code
      Can you please email me the code.. on my emailid alok.kumar@infralin.com

    9. #9 by Loren on May 17, 2013 - 5:43 am

      I would like to see your PHP code for getting the lat/log from a zip. Thanks!

    10. #10 by bala on August 5, 2013 - 12:14 pm

      Can you please email me the code.. on my emailid bala88204@gmail.com

    11. #11 by jonathan on October 25, 2013 - 6:26 pm

      Hi nice job! can you email me this code plz. My email is bobo_burnrs@hotmail.com

      ty have a nice day

    (will not be published)