2017-02-28 87 views
0

我正在构建一个地区搜索功能以显示来自特定城市的地区。用户将过滤城市页面上的内容。Google Places API中的城市级组件限制API

对于这个我使用谷歌地图的JavaScript API

此API在国家层面组成部分的限制。

var options = { 
types: ['(regions)'], 
componentRestrictions: {country: 'in'}}; 

现在在这种情况下,既然我已经知道这个城市,我想获得该特定城市onyl的当地结果。

是否有这个API在同一任何过滤>

回答

0

嗯,我也成功地实现它以下列方式。

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

document.addEventListener("DOMNodeInserted", function() { 
    $('.pac-container div').each(function() { 
     if($(this).text().toLowerCase().search(cityName.toLowerCase()) == "-1") { 
      $(this).hide(); 
     } 
    }); 
}); 

所以出来的结果是一个国家我过滤掉那些不符合cityName