title: How do i update content of infowindow in loop with setInterval
body: <p>I am having problem in updating the infowindow content everytime my loop runs with the specified setInterval.Every 1 second the content of the infowindow will change each marker array...but I am having problem If I put the closure in the if statement. after 5 minuets the browser will crash because of adding the listener in every 1 second.what I want is to update only the content of each marker.how would I do that.?</p>
  
  <p>Thank you in advance.</p>
  
  <pre><code>var map;
  var marker;
  var markerarray =[];
  
  setInterval(function(){
    $.ajax({
      type: "post",
      url: "vehiclecordinates.php",
      success: function(data){
        coordinates = data.latlng;
        vehiclename = data.vehiclename;
        heading      = data.heading;
        devname = data.vehiclename;
        thedate = data.trackdate;
  
        for (var i = 0; i &lt; coordinates.length; i++) {
          newcoordinate = new google.maps.LatLng(coordinates[i].split(",")[0],coordinates[i].split(",")[1]);
          if (markerarray[vehiclename[i]] &amp;&amp; markerarray[vehiclename[i]].setPosition){
  
            markerarray[vehiclename[i]].icon.rotation = parseInt(heading[i]);
            markerarray[vehiclename[i]].setPosition(newcoordinate);
  
            var con = '&lt;div style="font: 11px arial,tahoma,helvetica,sans-serif;"&gt;Vehicle Name:' + devname + '&lt;br/&gt;' +'Date='+thedate+'&lt;/div&gt;';
  
          }else {
            marker =  new MarkerWithLabel({
              map:map,
              labelClass: "mylabels",
              labelStyle: {opacity: 1.0},
              labelContent: '&lt;div&gt;'+ vehiclename[i]+'&lt;/div&gt;',
              icon:{
                path: google.maps.SymbolPath.CIRCLE,
              scale:.7,
              strokeColor: 'white',
              strokeWeight: .10,
              fillOpacity: 1,
              fillColor: '#404040',
              offset: '5%',
              rotation: parseInt(heading[i]),
              anchor: new google.maps.Point(10, 50)
              }
            });
            marker.setPosition(newcoordinate);
            markerarray[vehiclename[i]] = marker;
              var con = '&lt;div style="font: 11px arial,tahoma,helvetica,sans-serif;"&gt;Vehicle Name:' + devname + '&lt;br/&gt;' +'Date='+thedate+'&lt;/div&gt;';
  
          google.maps.event.addListener( marker, 'click', (function  (marker, con, infowindow) {
          return function () {
              infowindow.setContent(con);
              infowindow.open(map,  marker);
          };
          })( marker, con, infowindow));
          }
  
  
  
  
        }
      }
    });
  },1000);
  </code></pre>