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.


5 Comments Received
Thanks for this. I have been looking around for something like this for some time now..
Many thanks, this is a great little code.
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.
It may be temporary but seems to have gone. http://geo.localsearchmaps.com
Yup. This doesn’t seem to work anymore.
Leave A Reply