Error: useless setTimeout call (missing quotes around argument?)

Error: useless setTimeout call (missing quotes around argument?)

Firefox 给出错误 "Error: useless setTimeout call (missing quotes around argument?)",而在 Chrome 中它工作正常。我想将来自搜索结果的地址数组作为 'searchResultBox' div 元素中的数据。现在我将这些地址一一传递给 Google 映射 API 以获取地址。我使用 setTimeout 来克服 Google 的 'Over Query Limit' 错误。在 Chrome 中它工作正常,但 Firefox 给出错误 "Error: useless setTimeout call (missing quotes around argument?)"。我该怎么办?

var resturantids ='';
var logititude ='';
var  latitude ='';
var add ='';
var rest_name ='';
jQuery('.searchResultBox').each(function(){
resturantids += ''+jQuery(this).attr('data-resturantidsarr')+';';
logititude += ''+jQuery(this).attr('data-logtiresarr')+';';
latitude += ''+jQuery(this).attr('data-latiresarr')+';';
add += ''+jQuery(this).attr('data-addresses')+';';
rest_name += ''+jQuery(this).attr('data-listing-name')+';';

});

var resturantidsarr = new Array();
var logtiresarr=new Array();    
var latiresarr= new Array();
var addresses = new Array();
var resturantname = new Array(); 

resturantidsarr = resturantids.split(";");
logtiresarr = logititude.split(";");
latiresarr = latitude.split(";");
addresses = add.split(";");
resturantname = rest_name.split(";");

var popcontentdisplay;
var c=0;
var b=0;
var i=0;
var delaytime = 10000;
var nextAddress = 0;

var infowindow = new google.maps.InfoWindow();
var latlng = new google.maps.LatLng(latiresarr[0], logtiresarr[0]);
var mapOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var geocoder = new google.maps.Geocoder(); 
var map = new google.maps.Map(jQuery('#map_canvas')[0], mapOptions);
var bounds = new google.maps.LatLngBounds();


function geocodeAddress(resturantid, logtires, latires, address, resturant, next) { 
console.log(nextAddress);
console.log(address);
geocoder.geocode({'address': address}, function (results,status)    { 
if (status == google.maps.GeocoderStatus.OK) {

var addr = results[0].formatted_address;           
var p = results[0].geometry.location;
var addr2 = address.replace(/\+/g, ' ');
popcontentdisplay=resturant+" - \n"+addr2;

console.log(addr2);
console.log(' ');
console.log(' ');

resturantid2=resturantid;
if(logtires == 0 && latires == 0){ 
latires = results[0].geometry.location.lat();
logtires = results[0].geometry.location.lng();
}
var latlng = new google.maps.LatLng(latires, logtires);

var strpara;            
var digits2=resturantid2.toString().length; 
if( digits2 >= 5  ) {
strpara='id='+resturantid2;
} else   {
strpara='post_id='+resturantid2;
}                   
var contentString =  '<div> <a href="<?php echo site_url();  ?>/search-detail/?'+strpara+'"> '+popcontentdisplay +' </a> </div>';
b++;


var marker =  new google.maps.Marker({
position: latlng,
map: map,
clickable: true,               
title: popcontentdisplay,
});
google.maps.event.addListener(marker, 'click', getInfoCallback(map, contentString));
nextAddress++;

}
else {
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
delaytime += 5000;
//console.log(status);
} else {
console.log(status);
//delaytime += 10000;
console.log(nextAddress);
nextAddress++;
}   
}
next();
});
}

function theNext() {
if (nextAddress < addresses.length-1) {         
setTimeout(geocodeAddress(resturantidsarr[nextAddress],logtiresarr[nextAddress],latiresarr[nextAddress],addresses[nextAddress],resturantname[nextAddress], theNext), delaytime);  
} 
}
theNext();

function getInfoCallback(map, content) {
var infowindow = new google.maps.InfoWindow({content: content});
return function() {
// infowindow.setContent(content); 
infowindow.open(map, this);
};
}

您正在调用函数 geocodeAddress() 并将该调用的 return 值(即 undefined)传递给 setTimeout(),这将没有任何效果。

你的意思可能是这样的:

setTimeout(function () { geocodeAddress(...); }, delaytime);