You are on page 1of 1

Hello, I am trying to get data from json , and then remove it and load it again

every 3 seconds, thus refreshing the google maps markers


//get json data
function fetchData() {
var load = new XMLHttpRequest();
load.open("GET", "asd.json", false);
load.send(null);
var data = JSON.parse(load.responseText);
for (id in data.items) {
var item = data.items[id];
var mInfo = new google.maps.InfoWindow({
content: ''+item.name+''+item.text+''
});
var pMarker = new google.maps.Marker({
position: SanMap.getLatLngFromPo
s(item.pos.x, item.pos.y),
map: sm.map,
icon: 'icons/Icon_'+item.icon+'.
gif'
});
google.maps.event.addListener(pMarker, '
click', function() {
sm.map.setCenter(pMarker.positio
n);
mInfo.open(sm.map,pMarker);
});
markersArray.push(pMarker);
}
}
//function to remove markers below
var markersArray = [];
function clearOverlays() {
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
fetchData();
//Function to remove current markers, and load data again
function refresh() {
clearOverlays();
fetchData();
}
//refreshing every 3 seconds
setInterval(refresh(), 3000);
But it doesn't refresh. What am i doing wrong?

You might also like