【问题标题】:Google Places API - How to limit the search limit to just one cityGoogle Places API - 如何将搜索限制限制在一个城市
【发布时间】:2018-02-27 18:26:07
【问题描述】:

我不会将搜索限制限制在一个城市(例如“纽约”) 我需要有关 componentRestrictions 选项的帮助。 谢谢!

<script type="text/javascript">

    function initialize() {
        var options = {
            types: ['address'],
            componentRestrictions: {country: "us", locality: "new york"}
        };
        var input = document.getElementById('searchTextField');
        var autocomplete = new google.maps.places.Autocomplete(input, options);
    }

    google.maps.event.addDomListener(window, 'load', initialize);

</script>

【问题讨论】:

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


    【解决方案1】:

    您可以通过在输入示例之前添加 NY_ 来限制它,如果您想搜索华盛顿港,那么您的输入将是 NY_port_washington

    Example Link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      • 2015-09-03
      相关资源
      最近更新 更多