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.

    (will not be published)
    Security Code:

    1. No trackbacks yet.