Skip to content

Instantly share code, notes, and snippets.

@walkermalling

walkermalling/api timeout

Last active Aug 29, 2015
Embed
What would you like to do?
getPlaces: function(){
var _this = this;
var timeout = 0;
var index = 0;
loopRequest();
function loopRequest(){
// create request object
var request = {
location: _this.routeResult.routes[0].overview_path[index],
radius: _this.formView.radius * 1609.34,
types: [_this.formView.placeType],
keyword: _this.formView.keyword,
openNow: true
};
if(request.types === 'restaurant') request.minPriceLevel = 1;
_this.service.nearbySearch(request, function(results,status){
if (status === 'OVER_QUERY_LIMIT'){
// gradually increase timeout
timeout += timeout + 1;
} else{
// reset timeout
timeout = 0;
// for each returned place
for (var i = 0; i < results.length; i++) {
var thisPlace = results[i];
_this.addPlace(thisPlace);
}
}
// update progress bar
_this.updateProgress(index);
// loop, with delay if API limit reached
if(index++ < _this.routeResult.routes[0].overview_path.length){
setTimeout(loopRequest,timeout);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment