带有新API密钥的Google地方信息库OVER_QUERY_LIMIT

JDi*_*522 3 javascript google-maps google-places-api

我在我的JavaScript应用程序中使用Places库。当我使用该service.nearbySearch()方法查找附近的地方时,效果很好。然后,当我提出service.getDetails()请求时,我会获得OVER_QUERY_LIMIT每个请求的状态。在我的开发者控制台中,我可以跟踪对Google Maps JavaScript API v3的每个请求,但是我没有从places API获得任何结果。

以下是一些代码:

// How I load the library 
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=API_KEY"></script>

// My places request
var places = new google.maps.places.PlacesService(map);
var location = new google.maps.LatLng(lat, lng);
var request = {
    location: location,
    radius: radius,
    types: [type]
  };

places.nearbySearch(request, function(results, status, pagination) {

    if (status === google.maps.places.PlacesServiceStatus.OK) {
      for (var i = 0; i < results.length; i++) {

      // Get the details for each place
      var detailsRequest = { placeId: results[i].id }

      places.getDetails(detailsRequest, function(place, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
            console.log('PLACE', place)
        } else {
            console.log('STATUS', status)
        }        
    })              
  };
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

JDi*_*522 6

答案是我要求的.getDetails()方法太快了。文件

我遍历了数十个位置,并要求太多太多。通常,在OVER_QUERY_LIMIT错误发生之前,我只会得到60多个结果中的前10或12个。

我将呼叫移至.getDetails()标记的click事件。这样,一次只发送一个请求。