google places api - How to pause a FOR loop in Javascript in a function? -
there's query per second limit in google places api, need slow down loop sends requests:
function callback(results, status) {   if (status != google.maps.places.placesservicestatus.ok) {     alert(status);     return;   }       (var = 0, result; result = results[i]; i++) {     requestinfo(result);   } }   any idea how can that? i'm bit of newb.
recursive solution,
function requestinfowrapper(results, i) {     = + 1;     if (i >= results.length) {return};     requestinfo(results[i]);     settimeout(function() {requestinfowrapper(results, i);}, 1000); }   some example code test it,
   var results = ["test 1", "test 2", "test 3"];    function requestinfo(str) {console.log(str);}    requestinfowrapper(results, -1);   also integrated code be,
function callback(results, status) {     if (status != google.maps.places.placesservicestatus.ok) {         alert(status);         return;     }      requestinfowrapper(results, -1); }      
Comments
Post a Comment