title: marker.setposition with label
body: <p>I have the program below that reads aircraft coordinates from a txt file and places a number of markers on Google Maps. Every 2 sec it reads the txt file again and pushes the markers to the new aircraft locations. This works fine with the original markers "moving" to the new positions. What I would like to do is add a label to the marker to show the height of each aircraft. To do this I need to generate the label after the txt file has been read but when I do it doesn't delete the old markers but adds new markers.</p>
  
  <p>The portion of code below is working fine but without a variable labels. The relevant code is where var eplanezero is created. If I move this line of code anywhere within the setInterval(function (){ the eplanezero.setPosition will not function properly. I have tried dozens of various but nothing seems to work. Any thoughts appreciated. Note that this is only a portion of the code.</p>
  
  <pre><code>    moveMarker(map, playerIcon, enemyIcon);
  }
  
  function moveMarker(map, playerIcon, enemyIcon)
  {
  var eplanezero = new google.maps.Marker({map: map, icon: enemyIcon, label: "1"});
  
  setInterval(function ()
  {
      $.post("MISSION_ADMIN_radar.txt", function(dataenemy, status)
      {
      var latlnge = JSON.stringify(dataenemy);
      latlnge = latlnge.replace(/"/g,"");
      latlnge = latlnge.replace(/[\\r\\n]/g,"");
  
      CoordsEnemy = latlnge.split(";");
  
      var army = parseFloat(CoordsEnemy[0].substring(0));
      if (army == 2)//Own army = 1, Enemy = 2
          {
          var commaPos = CoordsEnemy[0].indexOf(',');
          var hyphenPos = CoordsEnemy[0].indexOf('+');
          var lat0 = parseFloat(CoordsEnemy[0].substring(4, commaPos));
          var long0 = parseFloat(CoordsEnemy[0].substring(commaPos + 1, CoordsEnemy[0].length));
          }
          eplanezero.setPosition(new google.maps.LatLng(lat0, long0));
  
          });
  }, 2000);
  </code></pre>
  
  <p>The altitude is obtained from the same array that holds the lat and long. However, to place the variable Alt into the marker, I have to create variable eplanezero in the setInterval function so that it updates it every 2 secs. When I do this, it will not <strong>move</strong> the marker but <strong>adds</strong> a new marker, leaving the original marker in the old position.</p>
  
  <p>The revised code is as follows:</p>
  
  <pre><code>    function moveMarker(map, playerIcon, enemyIcon)
  {
  //var eplanezero = new google.maps.Marker({map: map, icon: enemyIcon, label: "1"});
  
  var eplanezero = new google.maps.Marker({map: map, icon: enemyIcon, label: Alt});
  
  setInterval(function ()
  {
      $.post("MISSION_ADMIN_radar.txt", function(dataenemy, status)
      {
      var latlnge = JSON.stringify(dataenemy);
      latlnge = latlnge.replace(/"/g,"");
      latlnge = latlnge.replace(/[\\r\\n]/g,"");
  
      CoordsEnemy = latlnge.split(";");
  
      var army = parseFloat(CoordsEnemy[0].substring(0));
      if (army == 2)//Own army = 1, Enemy = 2
          {
          var commaPos = CoordsEnemy[0].indexOf(',');
          var hyphenPos = CoordsEnemy[0].indexOf('+');
          var Alt0 = parseFloat(CoordsEnemy[0].substring(hyphenPos + 1 , CoordsEnemy[0].length));
  
          var lat0 = parseFloat(CoordsEnemy[0].substring(4, commaPos));
          var long0 = parseFloat(CoordsEnemy[0].substring(commaPos + 1, CoordsEnemy[0].length));
      var eplanezero = new google.maps.Marker({map: map, icon: enemyIcon, label: Alt});
          }    
          eplanezero.setPosition(new google.maps.LatLng(lat0, long0));    
      });
  }, 2000);
  </code></pre>