Click here to Skip to main content
15,746,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is the current code i have the setInterval(function () {initMap();},5000); reloads the whole map not only the markers

<!DOCTYPE html >
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>customer location</title>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;

    <div id="map"></div>

    setInterval(function () {initMap();},5000);
      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
          downloadUrl('xml1.php', function(data) {
            var xml = data.responseXML;
            var 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() {
      , marker);

      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);

      function doNothing() {}
    <script async defer

What I have tried:

i have tried making a bindmarkers function but it does not work.
Updated 15-Apr-19 12:59pm

1 solution

Your code calls the code to initialise the map. Of course it does that. Change the code to clear and refresh the markers
Share this answer
Member 14097367 15-Apr-19 19:05pm    
yes i realize that i was trying to figure out how to change it to that the clear and refresh the thing is that this is my first time using java script and im not sure how everything works here

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