开发者

Best way to geocode UK postcode with Google Maps API?

开发者 https://www.devze.com 2022-12-30 10:53 出处:网络
What is the most effective an开发者_如何学JAVAd accurate way to geocode a UK postcode? Using the built in geocode object results in massively blurred results (lots of postcodes returning just a genera

What is the most effective an开发者_如何学JAVAd 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?


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");
}


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消