使用Google地图API对英国邮政编码进行地理编码的最佳方式是什么? [英] Best way to geocode UK postcode with Google Maps API?

查看:148
本文介绍了使用Google地图API对英国邮政编码进行地理编码的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对英国邮政编码进行地理编码最有效和准确的方法是什么?使用内置的地理编码对象会导致大量模糊的结果(大量邮政编码仅返回一般区域)。

是否有免费的英国邮政编码地理编码服务可以通过JavaScript?

解决方案

编辑:要更清楚地说明这是在谷歌搜索api中使用本地搜索,而不是google map api做更准确的地理编码。



最好的方法是使用Google Search Api。



如果您获得api密钥并完成所有设置: 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);

函数initialize()
{
localSearch = new GlocalSearch();
图标=新的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);
}
$ b $ **
*这可以是邮政编码或地址字符串
*
* /
函数plotAddress(地址)
{
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(地址+,英国);
}


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?

解决方案

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

这篇关于使用Google地图API对英国邮政编码进行地理编码的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆