如何以时间间隔删除旧标记并自动将其替换为新标记。我正在使用谷歌地图创建一个真正的跟踪器。`
var markersArray = [];
function initialize() {
var myLatlng = new google.maps.LatLng(39, -86);
var map = new google.maps.Map(document.getElementById('googleMap'), {
zoom: 1,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
$(function () {
$(document).ready(function(){
setInterval(function(){
$.ajax({
url: 'real.php', //the script to call to get data
//data: "",
dataType: 'json', //data format
success: function(data){ //on recieve of reply
var locations = data;
var infowindow = new google.maps.InfoWindow();
var marker, i;
deleteOverlays();
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
markersArray.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
});
}, 1000);
});
});
}
initialize();
如何删除我使用 clearOverlays 但地图中未显示任何标记的标记。谢谢。