In your code, all marker's click event listener will use the same (the last) value for "marker" and "infowindow" instance, that's why clicking any marker will always open the same info window on the same marker (#4).
You can create a new InfoWindow for each marker when it's clicked, but since its local variable infowindow would always be not initialized when calling the event listener function (because it preserves its activation frame, read http://econym.org.uk/gmap/closure.htm) you'd be creating a new infowindow on each click: for (var i = 0; i < 5; i++) { var point = new google.maps.LatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random()); var marker = new google.maps.Marker({map: globMap, position: point, title: ''+ i }); google.maps.event.addListener(marker, 'click', function() { var strContent = 'Position: ' + this.getPosition(); var infowindow = new google.maps.InfoWindow(); infowindow.setContent(strContent); infowindow.open(globMap, this); }); } } Also, not that since marker is not local to the event listener handler, I'm using "this" to get hold of each individual marker. However, "this" is tricky. You'd need to keep track of markers and infowindows in some sort of array/s to do this really well. Hoping you don't mind, I'll leave it for you :) Cheers, Miguel On Thu, Aug 12, 2010 at 14:41, Alec <golibr...@gmail.com> wrote: > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas- > microsoft-com:vml"> > <head> > <meta http-equiv="content-type" content="text/html; charset=utf-8"/ > > > <title>Google Maps JavaScript API Example: Simple Icon; And some > Errors :-( </title> > > <script type="text/javascript" src="http://maps.google.com/maps/api/js? > sensor=false <http://maps.google.com/maps/api/js?sensor=false>"></script> > > > <script type="text/javascript"> > > function initialize() { > > var myLatlng = new google.maps.LatLng(45.259399414, 34.545501709); > var myOptions = { > zoom: 4, > center: myLatlng, > mapTypeId: google.maps.MapTypeId.ROADMAP, > mapTypeControl: true, > mapTypeControlOptions: { > style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, > position: google.maps.ControlPosition.BOTTOM_RIGHT > }, > navigationControl: true, > navigationControlOptions: { > style: google.maps.NavigationControlStyle.ZOOM_PAN, > position: google.maps.ControlPosition.LEFT > }, > scaleControl: true, > scaleControlOptions: { > position: google.maps.ControlPosition.BOTTOM_LEFT > } > } > > globMap = new google.maps.Map(document.getElementById("bg_map"), > myOptions); > > // Create our "tiny" marker icon > // var bounds = globMap.getBounds(); - not work !!!!!!! > var center = globMap.getCenter(); > var southWest = new google.maps.LatLng (center.lat() - 10, > center.lng() - 10); > var northEast = new google.maps.LatLng (center.lat() + 10, > center.lng() + 10); > var lngSpan = 20; // northEast.lng() - southWest.lng(); > var latSpan = 20; // northEast.lat() - southWest.lat(); > for (var i = 0; i < 5; i++) { > > var strContent = 'InfoWindow(Marker) number = ' + i > + ';'; > > var point = new google.maps.LatLng(southWest.lat() + > latSpan * > Math.random(), > > southWest.lng() + lngSpan * Math.random()); > var marker = new google.maps.Marker({map: globMap, > position: point, > title: ''+ i }); > var infowindow = new google.maps.InfoWindow(); > infowindow.setContent(strContent); > infowindow.open(globMap, marker); > > google.maps.event.addListener(marker, 'click', > function() { > > infowindow.open(globMap, marker); > }); > } > } > > </script> > </head> > > <body onload="initialize();"> > Here error: > If you first close all "InfoWindow", and then "click" on the "Marker" > - does not work correctly.<br> > An example from the API vers 2 was correct.<br> > <br> > var bounds = globMap.getBounds(); - not work !!!!!!! > <br> > how to fix?<br> > all the best,<br> > Alexander<br> > > <div id="bg_map" style="width: 600px; height: 600px"></div> > </body> > </html> > > -- > You received this message because you are subscribed to the Google Groups > "Google Maps JavaScript API v3" group. > To post to this group, send email to > google-maps-js-api...@googlegroups.com. > To unsubscribe from this group, send email to > google-maps-js-api-v3+unsubscr...@googlegroups.com<google-maps-js-api-v3%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-maps-js-api-v3?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to google-maps-js-api...@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.