Google Places API - How to limit the search limit to just one city

邮差的信 提交于 2019-12-11 16:17:16

问题


I wont to limit the search limit to just one city (e.g "New York") and I need help with componentRestrictions options. Thanks!

<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>

回答1:


You can restrict it by adding NY_ Before your input example if you want to search Port Washington then your input will be NY_port_washington

Example Link



来源:https://stackoverflow.com/questions/49015517/google-places-api-how-to-limit-the-search-limit-to-just-one-city

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!