No addListener in a for loop. Try it the other way round: Write a createMarker function that can be called whenever you want to create a marker.
This function can also be called in a for loop. Here's one possible example http://www.wolfpil.de/marker-jumping.html On Jul 31, 6:04 am, Vaibhav <[email protected]> wrote: > Hello, > > I have to create markers in a loop and add click events to each of > them. > Can anybody tell me, how Can I do so? > > Here is following sample code: > ======================================================== > var marker1 = new Array(); > for (var i = 0; i < 10; i++) > { > alert("Hi"); > marker1[i] = new GMarker(new GLatLng(37.4419*i, -122.1419*i)); > alert("after"); > GEvent.addListener(marker1[i], "click", function() { > alert("Listener"); > marker1.openInfoWindowHtml("Some information on pin"); > }); > > map.addOverlay(marker1); > } > ========================================================= > Note: I've already created GMap2 object reference as map. > > The above code does not work. Please tell me how can solve this > problem. > > Regards, > Vaibhav --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---
