04 Mar 2007

By - 4,577 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.

4,577 comments on “Geocoding UK Postcodes with Google Map API
  1. Cheap viagra

    Viagra viagra online sildenafil online pharmacy Generic viagra pills levitra

  2. viagra

    Where buy viagra cialis Generic viagra online cheap viagra buy generic viagra generic viagra Viagra online without prescription usa

  3. Cialis online

    viagra online canada buy viagra online viagra vs cialis vs levitra viagra online canada pharmacy Cialis online

  4. porno

    Hmm it seems like your blog ate my first comment (it was extremely long) so I guess I’ll just sum it up what
    I had written and say, I’m thoroughly enjoying your blog.
    I as well am an aspiring blog blogger but I’m still new to everything.

    Do you have any suggestions for novice blog writers? I’d really appreciate it.

  5. buy viagra

    online payday loans no credit check buy generic viagra viagra online generic viagra for sale buy viagra online generic viagra

  6. generic levitra

    generic viagra online viagra viagra samples Viagra levitra online

  7. cialis sample

    Buy viagra Sildenafil viagra cialis generic viagra viagra online viagra online Viagra

  8. Cialis online

    viagra Viagra Cheap viagra online viagra Cialis no prescription

  9. Candy

    Throughout large flooding like Hurricane Katrina residents
    discovered themselves living on the second flooring or the
    roof with no access to meals or supplies.

  10. viagra vs cialis

    online pharmacy sale viagra Viagra viagra generic viagra online Cialis online

  11. Online viagra

    Viagra vs cialis cialis online Viagra viagra sildenafil order generic viagra online Viagra

  12. sildenafil

    generic viagra online canada pharmacy Viagra online generic viagra pharmacy Cheap viagra cheap levitra

  13. Cheap viagra online

    payday loans no credit check cheap viagra Canadian viagra cheap generic viagra online viagra viagra

  14. viagra

    Order viagra Sildenafil viagra cialis online cheap viagra viagra viagra pills Viagra 6 free sample

  15. Cialis

    viagra online canada pharmacy buy viagra online without script cheap viagra online generic viagra Cialis

  16. buy generic viagra

    buy generic viagra payday loans order viagra online viagra generic buy viagra online order generic viagra online

Leave A Comment

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