Is it possible that you are re-using the variable name (x) which ends up 
modifying the reference for it that is saved in the markers array ?
You could try to reduce it's scope by declaring "var x" and enclose it into 
brackets "{"
Ahmet

  ----- Original Message ----- 
  From: Thai Dang Vu 
  To: google-maps-js-api-v3@googlegroups.com 
  Sent: Thursday, March 11, 2010 4:09 PM
  Subject: [Google Maps API v3] Multiple InfoWindows and Markers


  I created 2 infoWindows and 2 markers like this:

  x = new google.maps.Marker({
      clickable: true, draggable: false, map: map,
      position: new google.maps.LatLng(40.81050, -74.38285), visible: true
  });
  x.setType('t');
  x.setAddress('130 State Route 10, East Hanover, NJ 07936');
  x.setPhone('973-887-3145');
  markers.push(x);
  x.setId(0);
  y = new google.maps.InfoWindow({
      content: '<div style="float: left;">hic hic hic ' + x.getId() +
               '</div>' +
               '<div style="clear: both;"></div>'
  });
  google.maps.event.addListener(x, 'click', function() {
      y.open(map,x);
  });

  x = new google.maps.Marker({
      clickable: true, draggable: false, map: map,
      position: new google.maps.LatLng(40.86159, -74.49681), visible: true
  });
  x.setType('k');
  x.setAddress('1711 State Route 10 East, Morris Plains, NJ 07950');
  x.setPhone('973-829-0197');
  markers.push(x);
  x.setId(1);
  y = new google.maps.InfoWindow({
      content: '<div style="float: left;">hic hic hic ' + x.getId() +
               '</div>' +
               '<div style="clear: both;"></div>'
  });
  google.maps.event.addListener(x, 'click', function() {
      y.open(map,x);
  });


  when I click on the first marker (the one with the id of 0), the infoWindow 
is popped-up, but it points to the 2nd marker and the content of that 
infoWindow is the content of the infoWindow for the 2nd marker.

  Did I do anything wrong? If the whole file is needed to see where I'm wrong, 
it's in the attachment.


  -- 
  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.

-- 
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.

Reply via email to