【问题标题】:Google Maps Autocomplete - only cities and postal code谷歌地图自动填充 - 仅限城市和邮政编码
【发布时间】:2019-01-01 21:07:48
【问题描述】:

是否可以将自动完成搜索仅限于城市和邮政编码?

这行不通:

autocomplete = new google.maps.places.Autocomplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
                    {types: ['(cities', '(postal_code)'], componentRestrictions: {country: "de"}});

也许这是对的?

autocomplete = new google.maps.places.Autocomplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
                    {types: ['(regions)'], componentRestrictions: {country: "de"}});

来源:https://developers.google.com/places/supported_types

但自动完成功能也会在我的受限国家/地区之外显示一些结果,为什么?

有什么建议吗?

解决方案

autocomplete = new google.maps.places.Autocomplete(
                    /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
                    {types: ['(regions)'], componentRestrictions: {'country': "de"}});

【问题讨论】:

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


    【解决方案1】:

    下面的代码是我问题的正确答案。

    autocomplete = new google.maps.places.Autocomplete(
                        /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
                        {types: ['(regions)'], componentRestrictions: {'country': "de"}});
    

    【讨论】:

    • 这也包括联邦州,有只有城市和邮政编码的解决方案吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 2014-06-16
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 2012-05-18
    • 2015-01-03
    相关资源
    最近更新 更多