Click here to Skip to main content
15,748,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently having problems clearing the past google maps marker i have a clearoverlays function but it does not work here is the code

var markers=[];

var customLabel = {
restaurant: {
label: 'R'
bar: {
label: 'B'

function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(17.1899, -88.534721),
zoom: 8
var infoWindow = new google.maps.InfoWindow;

// Change this depending on the name of your PHP or XML file

setInterval(function() {downloadUrl('xml1.php', function(data) {

var xml = data.responseXML;
markers = xml.documentElement.getElementsByTagName('marker');, function(markerElem) {
var id = markerElem.getAttribute('id');
var name = markerElem.getAttribute('name');
var address = markerElem.getAttribute('address');
var type = markerElem.getAttribute('type');
var point = new google.maps.LatLng(

var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = name

var text = document.createElement('text');
text.textContent = id
var icon = customLabel[id] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
label: icon.label
marker.addListener('click', function() {
infoWindow.setContent(infowincontent);, marker);



}, 0500);

function clearOverlays() {
for (var i = 0; i < markers.length; i++ ) {

function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;

request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
};'GET', url, true);

the set interval function just downloads the information from multiple people automatically from mysql database every half a second to plug in to the map it works great only that it leaves previous locations as markers on the map.

What I have tried:

ive tried making the clearoverlay run in a set interval as well but it does not work also i have tried putting the clearoverlay right after this
setInterval(function() {downloadUrl('xml1.php', function(data) {

but if i do this it does not update the locations until i manually refresh the page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900