Last active
August 29, 2015 14:05
-
-
Save walkermalling/a1494499805681acf481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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