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

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

问题描述

如何在谷歌地图自动完成地址api中根据国家和城市过滤地址.我可以根据国家/地区进行过滤,但无法根据国家和城市进行过滤.我正在使用以下代码:-

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.

Google 问题跟踪器中有一个功能请求来实现这一点.但是我们在那里看不到任何预计到达时间.

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

我建议您关注功能请求以添加您的投票并接收来自 Google 的更新.

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天全站免登陆