Best way to geocode UK postcode with Google Maps API?
Asked Answered
M

2

8

What is the most effective and accurate way to geocode a UK postcode? Using the built in geocode object results in massively blurred results (lots of postcodes returning just a general area).

Are there any free UK postcode geocoding services I can plug into via JavaScript?

Monogenic answered 14/5, 2010 at 9:2 Comment(1)
***I work for boundaries IO UK****, we have a rest service to do example what you ask. and returns GEO JSON: market.mashape.com/vanitysoft/uk-boundaries-ioAccroach
S
7

Edit: To be clearer this uses the local search in google search api, not the google maps api to do the geocoding which is much more accurate.

The best way is to use Google Search Api.

If you get an api key and get it all setup: http://code.google.com/apis/ajaxsearch/

var localSearch;
var map;
var icon;
var addressMarkerOptions;
google.load("search", "1");
google.load("maps", "2");
google.setOnLoadCallback(initialize);

function initialize()
{
  localSearch = new GlocalSearch();
  icon = new GIcon(G_DEFAULT_ICON);
  addressMarkerOptions = { icon:icon , draggable: false};
  map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  plotAddress("OX4 1FJ");
}

/**
* This takes either a postcode or an address string
*
*/
function plotAddress(address)
{
  localSearch.setSearchCompleteCallback(null, 
    function() {

      if (localSearch.results[0])
      {     
        var resultLat = localSearch.results[0].lat;
        var resultLng = localSearch.results[0].lng;
        var point = new GLatLng(resultLat,resultLng);
        var marker = new GMarker(point, addressMarkerOptions);
        map.addOverlay(marker);
        map.setCenter(point, 5, G_NORMAL_MAP);
      }
      else
      {
        alert('address not found');
      }
    });

  localSearch.execute(address + ", UK");
}
Schlosser answered 14/5, 2010 at 9:27 Comment(5)
I think the OP is finding that using the Google maps API yields very hazy results for UK postcodes. I personally have found the API to yield different results for a postcode than the results observed from the google maps website.Sennacherib
This isn't using the google maps api to do the geo coding. Its using the local search api which is much more accurate. I'll edit this to be clear.Schlosser
+1 brilliant, exactly what I was after worked superbly thank you! Are there restrictions on how many requests you can make in one day? I'd used this before but couldn't remember anything about it, but I recall there being a limitation of some kind? Anyway, thanks again, superb!Monogenic
No idea on the restrictions, but it will be on the google api site somewhere.Schlosser
Sadly the search api has been deprecated.Schlosser
S
-1

I believe Live/Bing/Windows maps' API gives a much more accurate placement for a UK postcode than the Google maps API does.

Alternatively, there are databases of UK postcode data available, although they're quite costly. There are some interesting comments on this post: http://jamiethompson.co.uk/web/2008/07/24/full-uk-postcode-database-for-free/

Sennacherib answered 14/5, 2010 at 9:37 Comment(3)
Additionally, there's a XML, JSON, JSONP webservice jamiethompson.co.uk/projects/2010/04/30/… The JSONP flavour being ideal for plugging directly into a JavaScript app.Sianna
Just got a downvote on this answer (4+ years later). I presume the info is no longer accurate.Sennacherib
Yeah the website is no longer available.Incommutable

© 2022 - 2024 — McMap. All rights reserved.