【发布时间】:2011-10-28 20:35:41
【问题描述】:
我需要一种使用英国邮政编码生成的 API v3 的简单方法来显示地图。无需搜索字段,每张地图只需一个静态邮政编码。
有没有人有好的方法来做到这一点?
【问题讨论】:
标签: javascript google-maps google-maps-api-3
我需要一种使用英国邮政编码生成的 API v3 的简单方法来显示地图。无需搜索字段,每张地图只需一个静态邮政编码。
有没有人有好的方法来做到这一点?
【问题讨论】:
标签: javascript google-maps google-maps-api-3
我遇到了类似的问题,把代码贴在这里:
how to use the google maps api with greasemonkey to read a table of addresses and trace the route?
看看它是否对你有帮助。
以下代码使用美国邮政编码返回状态,但相信您可以根据需要进行修改。
var geocoder = new google.maps.Geocoder();
function getState(zipcode) {
geocoder.geocode( { 'address': zipcode}, function (result, status) {
var state = "N/A";
for (var component in result[0]['address_components']) {
for (var i in result[0]['address_components'][component]['types']) {
if (result[0]['address_components'][component]['types'][i] == "administrative_area_level_1") {
state = result[0]['address_components'][component]['short_name'];
// do stuff with the state here!
document.getElementById('state').innerHTML = state;
return;
}
}
}
});
}
--- 已编辑 [28/10/2011] ---
好的。非常简单的例子,不需要代码。
click here.
您所要做的就是更改邮政编码 SW1A,上面写着center=SW1A,UK。
再简单不过了:)
【讨论】: