我想你可以帮我设置这个函数的超时时间。我设置的超时似乎会破坏循环。
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));
}
}