我以为你可以帮我设置这个功能的超时。我设置的超时似乎破坏了循环。
window.eqfeed_callback = function(results) {
for (var i = 0; i < results.features.length; i++) {
var earthquake = results.features[i];
var coords = earthquake.geometry.coordinates;
var latLng = new google.maps.LatLng(coords[1],coords[0]);
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: getCircle(earthquake.properties.mag)
});
map.panTo(latLng);
}
}
求助:通过定义一个函数来进行变量
window.eqfeed_callback = function(results) {
for (var i = 0; i < results.features.length; i++) {
var earthquake = results.features[i];
var coords = earthquake.geometry.coordinates;
var latLng = new google.maps.LatLng(coords[1],coords[0]);
(function(i, earthquake, coords, latLng) {
setTimeout(function() {
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: getCircle(earthquake.properties.mag),
animation: google.maps.Animation.DROP });
map.panTo(latLng);
}, i * 400);
}(i, earthquake, coords, latLng));
}
}
答案 0 :(得分:0)
以下是否适合您?当然,您必须在结果变量中传入有效数据才能使回调执行正常工作。
setTimeout(function() {
window.eqfeed_callback(results)
}, 4000);