如何在具有settimeout函数的闭包中表达这一点,以在运行API之前或之后创建2秒暂停。请注意,geocoder.geocode是异步的。
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{
}
});
}
}
答案 0 :(得分:2)
setTimeout (function ()
{
geocoder.geocode( ... );
}, 2000);