Skip to content

Instantly share code, notes, and snippets.

@walkermalling
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkermalling/a1494499805681acf481 to your computer and use it in GitHub Desktop.
Save walkermalling/a1494499805681acf481 to your computer and use it in GitHub Desktop.
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