Mustapha George
Mustapha George

Reputation: 2527

javascript closure with a settimeout function

How can I express this within a closure with a settimeout function to create a 2 second pause before or after running the API. Note that geocoder.geocode is asynchronous.

function srPerformGeocode(addressToArray, nextRecord){                             

        var address = addressToArray.join(",");
        console.log(address);                    

        if (geocoder){                                                   
            glDelay = true;
            geocoder.geocode({ 'address': address.trim() }, function
            (results, status) {
                // count number of geocodings attempted
                glGeocodeCount ++;                                                       
                if (status == google.maps.GeocoderStatus.OK){            
                }
                else{
                }
            });
        }
}   

Upvotes: 0

Views: 524

Answers (1)

James M
James M

Reputation: 16718

setTimeout (function ()
{
    geocoder.geocode( ... );

}, 2000);

Upvotes: 2

Related Questions