Я бы хотел добавить 1- 2-секундная задержка на каждой итерации следующего цикла.
<html>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<input id="start" type="submit"> </input>
<div id='status'></div>
<script>
var geocoder=new google.maps.Geocoder();
var glGeocodeCount = 0 ;
$(document).ready(function() {
$('#start').click(function() {
//srPerformGeocode("TD Tower, 55 King Street West, Toronto, ON, Canada, M5K 1A2");
for(x=0;x<20;x++){
srPerformGeocode("TD Tower, 55 King Street West, Toronto, ON, Canada, M5K 1A2");
}
return false;
});
});
function srPerformGeocode(address){
if (geocoder){
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK){
$('#status').prepend("Success : " + address + "<br/>");
}
else{
$('#status').prepend("Failed : " + address + "<br/>");
}
});
}
}
</script>
современное Решение JS:
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function slowedCode() {
console.log("Before Delay")
await this.timeout(Math.random() * 2000 + 500) // Wait random amount of time between [0.5, 2.5] seconds
console.log("After Delay")
}
async function slowedForLoop() {
const data = ["1","2","3","4","5"]
for (let d of data) {
console.log(d)
await this.timeout(Math.random() * 100 + 500)
}
}
единственные отступают, Вы, должны выполнить задержку из асинхронной функции.