【问题标题】:Google Places Autocomplete API Country RestrictionGoogle Places 自动完成 API 国家/地区限制
【发布时间】:2013-02-01 15:26:14
【问题描述】:

第一次在这里发布海报。使国家/地区限制在搜索字段中起作用时遇到了一些麻烦。我的代码目前是:

<script type="text/javascript"
    src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
    var mapOptions = {
        //center: new google.maps.LatLng(-33.8688, 151.2195),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById('map_canvas'),
    mapOptions);

    var input = document.getElementById('searchTextField');
    var autocomplete = new google.maps.places.Autocomplete(input);

    autocomplete.bindTo('bounds', map);
    // Autocomplete.
    function setupClickListener(id, types) {
        var radioButton = document.getElementById(id);
        google.maps.event.addDomListener(radioButton, 'click', function() {
            autocomplete.setTypes(types);               
        });
    }    
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

我需要怎么做才能按国家/地区进行限制?我试过添加:

   componentRestrictions: {country: 'us'}

这会完全停止自动完成工作,没有明显的语法错误。

如果它看起来很懒,请原谅我,但我对编程比较陌生,所以需要我能得到的所有帮助!我正在尝试在此处修改 API 的现有实例,因此没有对其进行编码,这无疑增加了我的困惑。

谢谢。

【问题讨论】:

    标签: google-maps-api-3 components restriction country


    【解决方案1】:

    使用等号代替冒号:

    var componentRestrictions = {country: 'us'};
    autocomplete.setComponentRestrictions(componentRestrictions);
    

    【讨论】:

    • 如何在安卓应用中做同样的事情?
    猜你喜欢
    • 1970-01-01
    • 2016-01-25
    • 2016-06-22
    • 2017-10-20
    • 2017-08-05
    • 2012-07-23
    • 2017-08-28
    • 2020-11-08
    • 1970-01-01
    相关资源
    最近更新 更多