错误:无用的setTimeout调用(参数周围缺少引号?)

时间:2015-05-25 10:04:03

标签: javascript jquery firefox google-maps-api-3 mozilla

Firefox发出错误“错误:无用的setTimeout调用(在参数周围缺少引号?)”在Chrome中工作正常。我想在搜索结果中创建一个地址数组作为'searchResultBox'div元素中的数据。现在我将这些地址逐个传递给Google地图API以获取地址。我使用了setTimeout来克服Google的“Over Query Limit”错误。在Chrome中它的工作正常,但Firefox给出了错误“错误:无用的setTimeout调用(参数周围缺少引号?)”。我该怎么办?

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);
};
}

1 个答案:

答案 0 :(得分:1)

您正在调用函数geocodeAddress()并将该调用的返回值(undefined)传递给setTimeout(),这将无效。

你可能意味着这样的事情:

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