Google Places API-如何将搜索限制限制为一个城市 [英] Google Places API - How to limit the search limit to just one city

查看:78
本文介绍了Google Places API-如何将搜索限制限制为一个城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不会将搜索限制限制为一个城市(例如纽约")并且我需要有关componentRestrictions选项的帮助.谢谢!

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>

推荐答案

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

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

示例链接

这篇关于Google Places API-如何将搜索限制限制为一个城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆