I'm using the Places libary in my javascript application. It works fine when I use the
service.nearbySearch()
service.getDetails()
OVER_QUERY_LIMIT
// 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)
}
})
};
}
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.