Google Map API v3 - 和地理编码(英国邮政编码)

时间:2011-10-27 17:07:41

标签: javascript google-maps google-maps-api-3

我需要一种简单的方法来显示地图,使用API​​ v3,它是使用英国邮政编码生成的。不需要搜索字段,只需要每个地图的静态邮政编码。

有没有人有这么好的方法呢?

1 个答案:

答案 0 :(得分:1)

我遇到了类似的问题并在此处发布了代码:

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

--- EDITED [28/10/2011] ---

确定。很简单的例子,不需要代码 click here

您需要做的就是更改邮政编码 SW1A ,其中显示center=SW1A,UK
不能比这更简单:)