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

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -