Google Maps API UK Postcode Geocoding

Mar
16

After recently delving in to the depths of the Google Maps API I found one real problem.  It appears that the API does not provide Geocoding for UK postcodes.  This is due to license issues, as The Post Office and Ordnance Survey own the copyright for this data and therefore a fee is required to obtain it.

In search of the solution

Having crawled the internet for a good while a came across the following article Emad Fanous.  This article details an API that has been developed to return geocoded addresses, postcodes etc.

This solution provided everything I required, does exactly what it says on the tin and is easy to implement to boot.  Now I did come across postcode lists like jibble for example, however, I felt that the API would provide a more complete solution (In the sense of data available) and was more interesting to use :-) .

the code

The code is very simple and is as follows:

function gmap_geocode_postcode(postcode){
  var s = document.createElement(‘script’);
  s.src = ‘http://geo.localsearchmaps.com/?cb=gmap_map_postcode&use=google2&country=uk&zip=’ + postcode;
  s.type = ‘text/javascript’;
  document.getElementsByTagName(‘head’)[0].appendChild(s);
}

function gmap_map_postcode(lon, lat){
  map.setCenter(new GLatLng(lon, lat), 13);
}

Here’s an example of the Geocoding for UK postcodes in action.

scalability

Now I wouldn’t say this solution will be massively scaleable, however, if you just require a simple address search and you do not believe it will be heavily used then this would be a good solution for you.

update

I have recently stumbled upon a payed for service called iShareMaps on Demand.  The service (for a small fee of around £423 a year) offers a scalable UK Geocoding service that may be usefull if anyone wishes to use geocoding on a high traffic site.

8 Responses to “Google Maps API UK Postcode Geocoding”

  1. Paul F says:

    Thanks for this. I have been looking around for something like this for some time now..

  2. Kyuuki says:

    Many thanks, this is a great little code.

  3. Jonny says:

    The people working on the location module for drupal have been experimenting with the GeoNames service – http://www.geonames.org – which provides free postcode data for many countries including the UK and is either downloadable or accesible via an API.

  4. Dave says:

    It may be temporary but seems to have gone. http://geo.localsearchmaps.com

  5. JR says:

    Yup. This doesn’t seem to work anymore.

  6. Rhys says:

    You can still do it with a Google localsearch object: http://wheresrhys.co.uk/2009/08/where-you-headin-luv/

  7. Myview says:

    Google API free does not have a UK license for postcodes hence the accuracy of using Google maps for store Locators is very poor. They also cannot Gecode Ireland, Developers and agency’s have awful get rounds which often show US towns instead of UK as only based on the first 4 digits of a postcode.

    In all, no professional would use Google as there are specialists such as Bing and ViaMichelin would have the full kit available for business’s

  8. Andrew Scott says:

    Google basis (free) does not provide address verification (Geocoding) as there is no UK postcode license.

    This means postcode searches are very in-accurate. The proximity search is very poor, even for town searches, often not recognising locations.

    This is why Google have a premier and a enterprise solution which still is more expensive and not as good as business mapping specialists like bIng and Via Michelin who also have API’s.

    As a free lance developer, so serious business would use Google as the system is weak and really provides a watered down solution.

Leave a Reply