I would like to add a 500ms pause between each iteration of the first $.each
I'm not sure how to apply this solution: How to add pause between each iteration of jQuery .each()?
to my particular case:
function iterateAddresses () {
var time = 500;
$.each( addresses_google, function( index, value ) {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin],
destinations: value,
travelMode: 'DRIVING'
},
callback
);
function callback(response, status) {
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
for (var i = 0; i < origins.length; i++) {
var results = response.rows[i].elements;
for (var j = 0; j < results.length; j++) {
var element = results[j];
if(element.status == "NOT_FOUND"){
var distance = 0;
} else {
var distance = element.distance.value;
}
if(distance > radius){
// Store postids in array
postids_to_hide.push(
addresses_postids[index][j]
);
// Hide elements where postid is in the postids_to_hide arrays
$.each( postids_to_hide, function( index, value ) {
$(".main_short_post_div").filter(function(){
return $(this).attr('data-post-id') === value;
}).hide();
});
} // end if d < r
} // end for j
} // end for i
} // end callback function
}); // end each addresses_google
}; // end iterateAddresses
iterateAddresses();