Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Places API中的城市级组件限制_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript Google Places API中的城市级组件限制

Javascript Google Places API中的城市级组件限制,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我正在构建一个地区搜索功能,以显示特定城市的地区。用户将过滤城市页面上的内容 为此,我使用谷歌地图JavaScript API 此API在国家/地区级别具有组件限制 var options = { types: ['(regions)'], componentRestrictions: {country: 'in'}}; 现在在这个例子中,因为我已经知道了这个城市,我想得到这个特定城市onyl的局部性结果 此API中是否有相同的过滤器>当前没有用于Places API中城市的组件过滤器 您可以

我正在构建一个地区搜索功能,以显示特定城市的地区。用户将过滤城市页面上的内容

为此,我使用谷歌地图JavaScript API

此API在国家/地区级别具有组件限制

var options = {
types: ['(regions)'],
componentRestrictions: {country: 'in'}};
现在在这个例子中,因为我已经知道了这个城市,我想得到这个特定城市onyl的局部性结果


此API中是否有相同的过滤器>

当前没有用于Places API中城市的组件过滤器

您可以在公共问题跟踪器中看到此功能的功能请求。看一看并用星号添加您的投票

作为一种解决方法,您可以尝试使用autocomplete的城市边界和strictBounds属性:


我确实通过以下方式实现了这一目标

我过滤掉了不包含所选城市的结果

document.addEventListener("DOMNodeInserted", function() {
    $('.pac-container div').each(function() {
        if($(this).text().toLowerCase().search(cityName.toLowerCase()) == "-1") {
            $(this).hide();
        } 
    });
});
因此,从一个国家的结果中,我过滤掉了那些与城市名称不匹配的结果