【问题标题】:Retrieve More Data from Google Map with the radarSearch method and getDetails method使用radarSearch方法和getDetails方法从谷歌地图中检索更多数据
【发布时间】:2017-04-04 20:30:51
【问题描述】:

请问在使用能检索200条结果的radarSearch方法和getDetails方法时,如何从谷歌地图获取10条以上的数据结果?我希望所有标记信息都列在地图下方的空白处。但是,我只得到了 10 个。我可以知道问题吗? 10 个结果保持不变,并且在浏览器刷新几次时可能只更改其中 1 个。

这是我用来从 Google 地图检索信息并创建标记的代码。我使用雷达搜索方法进行搜索。

   function callback(results, status) {
    if (status !== google.maps.places.PlacesServiceStatus.OK) {
      console.error(status);
      return;
    }
    for (var i = 0, result; result = results[i]; i++) {
      addMarker(result);
    }
  }

  function addMarker(place) {
    var placesList = document.getElementById('test');
    var marker = new google.maps.Marker({
      map: map,
      position: place.geometry.location,
      icon: {
        url: 'http://maps.gstatic.com/mapfiles/circle.png',
        anchor: new google.maps.Point(10, 10),
        scaledSize: new google.maps.Size(10, 17)
      }
    });


      service.getDetails(place, function(result, status) {
        if (status !== google.maps.places.PlacesServiceStatus.OK) {
          console.error(status);
          return;
        }

        iname = result.name;
        iLatitude = [result.geometry.location.lat()];
        iLongitude = [result.geometry.location.lng()];
        iAddress = [result.formatted_address];

      placesList.innerHTML += '<li>' + iname +'&nbsp;&nbsp;&nbsp;&nbsp;'+ iAddress + '</li>';
      });
  }

结果的屏幕截图。 The marker result is nearly 200, while the listed down data only consists of 10

【问题讨论】:

  • 地方服务有配额和速率限制(检查返回的状态,你正在记录它)
  • @geocodezip,先生,是不是因为 getDetails 获得了配额?正如我从文档中知道的那样,搜索方法得到了配额,但没有明确说明 getDetails 的配额。楼主,能不能详细解释一下。谢谢。
  • 所有 google 的服务都有配额和速率限制,getDetails 也不例外(你应该在第 10 项之后记录状态OVER_QUERY_LIMIT
  • @geocodezip,先生,我可以用您在论坛stackoverflow.com/questions/14014074/…提出的解决方案解决OVER_QUERY_LIMIT问题吗?

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


【解决方案1】:

其实问题是由于OVER_QUERY_LIMIT的问题,发送请求的时间延迟可以绕过,可以实现setTimeout方法来避免OVER_QUERY_LIMIT的问题。

替换为下面的代码。可以检索地图上的所有标记数据,(目前我在谷歌地图上有148个餐厅标记)

   service.getDetails(place, function(result, status) {
        if (status === google.maps.places.PlacesServiceStatus.OK) {

        iname = result.name;
        iLatitude = [result.geometry.location.lat()];
        iLongitude = [result.geometry.location.lng()];
        iAddress = [result.formatted_address];

        placesList.innerHTML += '<li>' + iname + ''+ iAddress + '</li>';
        }

        else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
        setTimeout(function() {
            addMarker(place);
        }, 200);
    }
      });

【讨论】:

    猜你喜欢
    • 2015-04-15
    • 2018-10-11
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    相关资源
    最近更新 更多