title: Google Maps API V3 Polyline Event Listener Params Not Passed When Loading Multiple Lines From Array
body: <p>I've successfully added a handler to the click event of polylines I've added to Google Maps (V3) if I code them to be added one at a time, but if I make a for loop to simply iterate through my data, it fails.</p>
  
  <p>Working demos:</p>
  
  <p><a href="http://www.ikfoundation.org/demo/works.html" rel="nofollow">http://www.ikfoundation.org/demo/works.html</a></p>
  
  <p><a href="http://www.ikfoundation.org/demo/fails.html" rel="nofollow">http://www.ikfoundation.org/demo/fails.html</a></p>
  
  <p>Code is identical on each apart from the bit that draws the lines: </p>
  
  <p>Works:</p>
  
  <pre><code>var linePts = [[
  new google.maps.LatLng(59.454924068851290, 17.094726562500000),
      new google.maps.LatLng(55.984639327677950, 17.270507812500000),
        ],[
  new google.maps.LatLng(51.081191044453350, 26.938476562500000),
  new google.maps.LatLng(62.112946929861720, 26.586914062500000)
        ]];
  
  // Draw the lines...  
  
  elines[0] = new google.maps.Polyline({
          path: linePts[0],
          strokeColor: "#0000ff",
          strokeOpacity: 1.00,
          strokeWeight: 7,
          clickable: true,
          editable: true,
          geodesic: true,
          zIndex: 1,
          map: map,
          myID: 0
      });
  
  
  
  google.maps.event.addListener(elines[0], 'click', function()
  {
      lineClick(elines[0]);
  });
  
  elines[1] = new google.maps.Polyline({
          path: linePts[1],
          strokeColor: "#0000ff",
          strokeOpacity: 1.00,
          strokeWeight: 7,
          clickable: true,
          editable: true,
          geodesic: true,
          zIndex: 1,
          map: map,
          myID: 1
      });
  
  google.maps.event.addListener(elines[1], 'click', function()
      {
          lineClick(elines[1]);
      });
  
  function lineClick(line)
  {
      alert("Line clicked with myID=" + line.myID);
  }
  </code></pre>
  
  <p>Fails (i excluded the same line point definition array which is identical to that shown abovem, and the lineClick function, again identical in both):</p>
  
  <pre><code>for (var i=0; i&lt;=1; i++)
  {       
  elines[i] = new google.maps.Polyline({
              path: linePts[i],
              strokeColor: "#0000ff",
              strokeOpacity: 1.00,
              strokeWeight: 7,
              clickable: true,
              editable: true,
              geodesic: true,
              zIndex: 1,
              map: map,
              myID: i 
          });
  
  google.maps.event.addListener(elines[i], 'click', function()
          {
              lineClick(elines[i]);
          });
  }
  </code></pre>
  
  <p>What have I done wrong? Both are using the same exact variable names and indexes in those variables. And everything works perfectly as you can see in my example links, apart from the click listener. Which fails in the latter "fails" version because it seems that the polyline is not being passed at all to the lineClick function (you need to run a java debugger to see the error).</p>
  
  <p>Thank you!</p>