title: Showing same infowindow for every marker google maps api
body: <p>I am using Google Maps API, I would like to show an infowindow for every marker.</p>
  
  <p>But the problem is the same content is showing for every marker infowindow. i.e., the last string of an array is showing in infowindow even though I have used function <code>bindInfoWindow()</code> it is not working:</p>
  
  <p>I am using Google Maps API, I would like to show an infowindow
  for every marker.</p>
  
  <p>But the problem is the same content is showing for every marker infowindow.i.e., the last string of an array is showing in infowindow even though I have used function <code>bindInfoWindow()</code> it is not working:</p>
  
  <pre><code>var poly;
  var map;
  var infodatajson = [
    17.4172192, 78.401285,
    17.418407, 78.401629,
    17.418090, 78.400610,
    17.417865, 78.398234
  ];
  
  // for center the map   
  function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      center: {
        lat: 17.4172192,
        lng: 78.401285
      }
    });
  
    // for polyline
    var flightPlanCoordinates = new Array();
  
    for (i = 0; i &lt; infodatajson.length; i += 2) {
      var point = new google.maps.LatLng(infodatajson[i], infodatajson[i + 1]);
      flightPlanCoordinates.push(point);
    }
  
    poly = new google.maps.Polyline({
      path: [new google.maps.LatLng(17.4172192, 78.401285),
        new google.maps.LatLng(17.418407, 78.401629),
        new google.maps.LatLng(17.418090, 78.400610),
        new google.maps.LatLng(17.417865, 78.398234)
      ],
      geodesic: true,
      strokeColor: '#0000FF',
      strokeOpacity: 1.0,
      strokeWeight: 3,
    });
  
    var infowindow;
    var infodata;
    var marker;
  
    // for markers
    for (var i = 0, ln = infodatajson.length; i &lt; ln; i += 2) {
  
      infodata = infodatajson[i] + ", " + infodatajson[i + 1];
  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(infodatajson[i], infodatajson[i + 1]),
        map: map,
        title: infodatajson[i] + ", " + infodatajson[i + 1],
      });
  
      infowindow = new google.maps.InfoWindow({});
  
      //function bindInfoWindow(marker, map, infowindow, infodata) {           
       marker.addListener('click', function() {
       infowindow.setContent(infodata);
       infowindow.open(map, this);
     });
      //}
    }
  
    poly.setMap(map);
  }
  </code></pre>