如何根据谷歌地图自动完成地址API中的国家和城市过滤地址 [英] how to filter address according country and city in google maps autocomplete address api

查看:178
本文介绍了如何根据谷歌地图自动完成地址API中的国家和城市过滤地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在谷歌地图自动完成地址API中根据国家和城市过滤地址。
我可以按照国家来解决过滤问题,但我无法根据国家和城市来解决过滤问题。我使用以下代码: - $ / $>

  var autocompleteFrom; 
$(document).ready(function(){
var options = {
types:['geocode'],
componentRestrictions:{country:IL}
$;
var inputFrom = document.getElementById('Address');
autocompleteFrom = new google.maps.places.Autocomplete(inputFrom,options);
google.maps.event。 addListener(autocompleteFrom,'place_changed',fillAddrss);
});


解决方案

没有办法将城市过滤器应用到位目前自动完成。



功能请求在谷歌问题跟踪器中做到这一点。不过,我们无法在此处看到任何ETA。



我可以建议您关注功能请求,以添加您的投票并接收Google的更新。



作为一种解决方法,您可以通过应用strictBounds参数的城市边界定义城市边界和过滤结果。

  var options = {
bounds:cityBounds,
strictBounds:true,
types:['geocode'],
componentRestrictions:{country:IL}
};

详情请参阅文档:

https://developers.google.com/maps/documentation/javascript/参考#AutocompleteOptions


How to filter address according country and city in google maps autocomplete address api. i am able to address filter according country but i am not able to address filter according country and city. I am using following code:-

 var autocompleteFrom;
    $(document).ready(function () {
        var options = {
            types: ['geocode'],
            componentRestrictions: { country: "IL" }
        };
        var inputFrom = document.getElementById('Address');
        autocompleteFrom = new google.maps.places.Autocomplete(inputFrom, options);
        google.maps.event.addListener(autocompleteFrom, 'place_changed', fillAddrss);
    });

解决方案

There is no way to apply a city filter in place autocomplete at the moment.

There is a feature request in Google issue tracker to make this happen. However we cannot see any ETA there.

I can suggest staring the feature request to add your vote and receive updates from Google.

As a workaround you can define city bounds and filter results by city bounds applying a strictBounds parameter

var options = {
    bounds: cityBounds,
    strictBounds: true,
    types: ['geocode'],
    componentRestrictions: { country: "IL" }
};

Please refer to docs for further details:

https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions

这篇关于如何根据谷歌地图自动完成地址API中的国家和城市过滤地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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