04 Mar 2007

By - 397 Comments

Notice: As a few people have pointed out, this announcement from Google means Geocoding is now built in. Yet as more people have pointed out – it kinda sucks accuracy wise (think over a mile off on some postcodes!), whereas my method continues to be accurate.

Google Maps API provides a geocoding feature, for finding the latitude and longitude of places or addresses; but it does not work for UK postcodes. This is thanks to Royal Mail who have a copyright on the data, and are very restrictive with their (expensive) licenses for it.

There are various solutions out there for using 3rd party services and importing the data to be used with Google Maps, or for using community built databases for the info. However, I’ve had a few people ask me about doing it just though Google.

It is possible — Google AJAX Search API does provide geocoding for UK postcodes. We need to use the two APIs in harmony to achieve our result.

So here it is.

Step by step

I’ll assume you already know how to use Google Maps API, and you came here just looking how to add geocoding for the UK.

Step 1.

Grab a two API keys, if you already have your Google Maps API key, just grab an AJAX search key. You can get them here:



Step 2.

Google will give you a sample page, you need to stick your two API keys at the top of the page, followed by a reference to your Javascript file:


Ensure the reference to your Javascript file comes after the two API keys.

Step 3.

In addition to the Google Maps API stuff, you need to stick a reference to Google local search at the top of your Javascript file:


You can grab my Javascript file right here, but remember you’ll need to change the API keys.

Step 4.

The key to this Geocoder is only a single function:


It takes 2 arguments; [code]]czo4OlwicG9zdGNvZGVcIjt7WyYqJl19[[/code] is the postcode you want to look for, and [code]]czoxNzpcIiBjYWxsYmFja0Z1bmN0aW9uXCI7e1smKiZdfQ==[[/code] is the function you wish to run on the results.

Why is it necessary to do it this way? It is the way AJAX, and thus Google AJAX Search API, works – the request is sent, and a callback function is designated to handle the results returned, when they are ready.

In our case, the callback function can do whatever you want with the results, which will come in the format of a [code]]czo3OlwiR0xhdExuZ1wiO3tbJiomXX0=[[/code] (often just called a point); I’ve supplied 2 sample functions, [code]]czoxOTpcIiBwbGFjZU1hcmtlckF0UG9pbnRcIjt7WyYqJl19[[/code] and [code]]czoxNjpcInNldENlbnRlclRvUG9pbnRcIjt7WyYqJl19[[/code] which do pretty much what they sound like they do.

Step 5.

Putting aside accessibility and graceful degradation for the sake of simplicity in this tutorial, the last step we need is just to add some hooks into our Javascript:


We have a field for inputting a postcode, and I’ve added a button for placing a marker there. Where I have [code]]czoxODpcInBsYWNlTWFya2VyQXRQb2ludFwiO3tbJiomXX0=[[/code] you can put a reference to your own function, or you can even add a function right in there, like this:



If you are coming in from an RSS reader, either visit this blog post on the site, or see the demo page.



Until Royal Mail sort get their act together, and relax the licensing agreement, hopefully this will help people who want a ‘pure’ Google solution and hadn’t come across this option. Please use the comments section to let me know if you are using this, or if you have any improvements or suggestions.

397 comments on “Geocoding UK Postcodes with Google Map API
  1. 最近記事


  2. 最近記事


  3. 詳しくは


  4. 続きを読みます

    それは$ 50のレベルを突破したように、標準的な運賃、金融プレスを支配し、それらの予測した$ 30と低いために呼び出します。

  5. 関連記事


  6. 関連リンク


  7. 詳しくは


  8. Buy viagra

    Buy viagra Buy generic viagra cheapest cialis viagra online viagra online viagra side effects Viagra

  9. expedition path

    Your insurance compamy might additionally supply tranning training courses for
    you as well as your workers for free.

  10. bride radar

    Greece is blessed with some extraordinary organic fruit and vegetables, including olives
    and olive oil, veggies and herbs, yoghurts and also cheeses, as well as
    the cuisine shows this, relying on characteristic, organic items.

  11. eliminate split

    The insurance also covers any trade plates registered to you
    that have actually been notified to your insurer.

  12. sildenafil

    generic viagra sildenafil citrate Generic viagra pills levitra cialis viagra

  13. nghqcgbiel

    Geocoding UK Postcodes with Google Map API – Tom Anthony
    nghqcgbiel http://www.gwx3n8awfn40mg7w071h24774lql783js.org/

  14. nearby

    As opposed to remaining in a resort loaded with other visitors, consuming imported food as
    well as taking foreign beverages, you will completely uncover
    which the rich culture in this part of the world needs to offer,
    experience time among several of the most panoramic landscapes in the world
    as well as still have the deluxe and liveliness you anticipate from a genuinely excellent

  15. generic viagra

    Buy viagra online buy cialis cheap Viagra online viagra online generic viagra vagra Viagra online fast

  16. generic viagra

    generic viagra Generic viagra order generic viagra online levitra

  17. buy viagra online no prescription

    top payday loans online Discount viagra viagra online credit card buy generic viagra buy viagra canada

  18. cheap viagra

    viagra online cheap viagra online order viagra online Cialis online

  19. http://blog.umy.ac.id/choirul/2011/08/21/sisa-hari-ramadhanku/

    Getaway clubs buy holidays at greatly affordable rates and afterwards market these to their members, normally with last minute offers where the greatest discount rates are found.

  20. marine

    Bollington Electric motor Claims will certainly keep you educated of your automobile repairs’ progress.

  21. Viagra generic

    viagra generic payday loans online no faxing viagra online viagra generic viagra

  22. Buy viagra

    buy generic viagra Viagra sildenafil generic levitra online

  23. Viagra online

    viagra online cheap buy viagra generic viagra online Cialis online

Leave A Comment

Your email address will not be published. Required fields are marked *