【问题标题】:Google Maps JavaScript API - Display Zip Code instead of United StatesGoogle Maps JavaScript API - 显示邮政编码而不是美国
【发布时间】:2015-04-11 18:57:33
【问题描述】:

如何在同一个文本框中显示包含邮政编码的地址?例如:123 main st, Atlanta, GA 30305。 这就是我所拥有的: //how to get google places autocomplete to work if the textbox is initially hidden and should be shown only after a postback

     var prm = Sys.WebForms.PageRequestManager.getInstance();
     prm.add_initializeRequest(InitializeRequest);
     prm.add_endRequest(EndRequest);
     function InitializeRequest(sender, args) {
     }
     // fires after the partial update of UpdatePanel
     function EndRequest(sender, args) {
         initialize();
     }
    function initialize() {
        var defaultBounds = new google.maps.LatLngBounds(
            new google.maps.LatLng(33.847037, -84.393539));
        var origin_input = document.getElementById('saddr');
        var options = {
            bounds: defaultBounds,
            types: ['address'],//Addresses only
            componentRestrictions: { country: 'us' }};
        var autocomplete_origin = new google.maps.places.Autocomplete(origin_input, options);
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    function updateAddressField()
    {
        var addrs = document.getElementById('saddr').value;
        document.getElementById('hdnAddress').value = addrs;
    }
</script>

【问题讨论】:

    标签: javascript asp.net google-maps


    【解决方案1】:

    嗯,我不知道你说的是哪种文本框,但是如果你想通过自动完成获取邮政编码,这里是你的答案:

    Link

    【讨论】:

    • 我说的是文本框,上面写着:输入您的地址。我知道选择地址后如何获取 zip。
    • 所以当你开始输入地址时,google显示的地址是没有邮编的。可证明 var options = {...} 中有一个参数将显示邮政编码。感谢您的回复
    猜你喜欢
    • 2018-01-03
    • 2011-11-28
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2019-02-25
    • 2011-05-19
    相关资源
    最近更新 更多