【问题标题】:City Level Component Restriction in Google Places APIGoogle Places API 中的城市级组件限制
【发布时间】:2017-02-28 13:32:38
【问题描述】:

我正在构建一个位置搜索功能来显示来自特定城市的位置。用户将过滤城市页面上的内容。

为此,我正在使用 Google Maps JavaScript API

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

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

现在在这种情况下,由于我已经知道这个城市,我想获得那个特定城市的位置结果。

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

【问题讨论】:

    标签: javascript google-maps google-maps-api-3


    【解决方案1】:

    Places API 目前没有城市组件过滤器。

    您可以在公共问题跟踪器中看到对此的功能请求。看看ticket 4433 并加注星标以添加您的投票。

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

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

    【讨论】:

      【解决方案2】:

      嗯,我确实设法通过以下方式实现了它。

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

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

      因此,我从一个国家/地区的结果中过滤掉了那些与cityName 不匹配的结果

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-14
        • 2013-09-09
        • 2019-01-27
        • 2013-05-07
        • 2012-05-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多