下面的代码在 Firefox 和 IE9 上运行良好,但在 IE8 上更新标记时出现问题。我收到“SCRIPT16389:未指定的错误。main.js,第 20 行字符 313”,并且一旦创建的标记不会使用新的数据集进行更新
我的 newdata.json 格式是
{
"points": [
{
"lat": "-28.0000",
"long": "133.1500",
"id": 0
},
{
"lat": "-28.4710",
"long": "153.3443",
"id": 1
}
]
}
下面是获取 json 并使用聚类显示点的脚本
var map=null;
var markersArray = [];
var markerCluster= null;
google.load('maps', '3', {
other_params: 'sensor=true'
});
google.setOnLoadCallback(initialize);
function initialize() {
var mapcentre = new google.maps.LatLng(-29,135);
var mapOptions = {
zoom: 5,
center: mapcentre,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
startTimer();
}
function startTimer(){
setInterval(function() {
deleteOverlays();//should delete any existing point and clear the cluster
addMarker();
},3000);
}
function addMarker() {
$.ajax({
type: "GET",
url: "newdata.json",
async: false,
dataType: "json",
success: function(data){
for (var i = 0, dataPoint; dataPoint = data.points[i]; i++) {
var latLng = new google.maps.LatLng(dataPoint.lat,dataPoint.long);
var marker = new google.maps.Marker({
position: latLng
});
markersArray.push(marker);
}
markerCluster = new MarkerClusterer(map, markersArray);
}
});
}
// Deletes all markers in the array by removing references to them
function deleteOverlays() {
if (markersArray.length > 0) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
if(markerCluster!= null) {
markerCluster.clearMarkers();
}
}
在 IE8 上,地图加载正常,初始数据显示正常,但新数据没有更新,所以我猜 deleteOverlays 有问题?