JDillon522 JDillon522 - 11 months ago 100
Javascript Question

Google Places Library OVER_QUERY_LIMIT with new API key

I'm using the Places libary in my javascript application. It works fine when I use the

service.nearbySearch()
method to look up nearby places. When I then go to make a
service.getDetails()
request I get an
OVER_QUERY_LIMIT
status for each request. In my Developer Console, I can track every request made to the Google Maps JavaScript API v3, but I dont get any results from the places API.

Heres some of the code:

// 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)
}
})
};
}


Any ideas?

Answer Source

The answer was that I was requesting the .getDetails() method too fast. Docs.

I was iterating over dozens of locations and requesting too many too fast. Often times I would only get the first 10 or 12 our of 60+ results before the OVER_QUERY_LIMIT error.

I moved the call to .getDetails() to the click event for the marker. That way only one request is sent at a time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download