On Sep 11, 10:03 am, Paul Skinner <[email protected]> wrote:
> Basic layout:
> Multiple markers each with own info window.
> Marker/info window data held in array.
>
> Loop to read through and add markers/info windows to map (upon click
> for the latter).
>
> Problem:
> Info windows don't open upon click of attached marker.
>
> Other info:
> The markers themselves load fine.
>
> Link:http://paulstestarea.co.uk/
>
> Code:
> function addPoints(map) {
>         var newpoints = new Array();
>         var infowindow = new Array();
>
>         newpoints[0] = new Array(51.708735945002054, 0.245819091796875,
> 'Epping Ongar Railway', 'This is a test');
>         newpoints[1] = new Array(51.70522554664541, 0.23843765258789062,
> 'test', 'Test');
>
>         for(var i = 0; i < newpoints.length; i++)
>         {
>                 var popuphtml = newpoints[i][3];
>                 var popuptitle = newpoints[i][2];
>
>                 var popupposition = new google.maps.LatLng(newpoints[i]
> [0],newpoints[i][1]);
>                 var marker = new Array();
>                 marker[i] = new google.maps.Marker({
>
>                         position: popupposition,
>                         map: map,
>                         title: popuptitle
>
>                 });
>
>                 /** InfoWindow Stuff **/
>                 var popuphtml2 = "<div id=\"popup\">" + popuphtml + "<\/div>";
>
>                 infowindow[i] = new google.maps.InfoWindow({
>                 content: popuphtml2,
>                 maxWidth: 300
>                 });
>
>                 var infowindow2 = infowindow[i];
>
>                 google.maps.event.addListener(marker[i], 'click', function() {

alert("marker["+i+"] click") always says 2...
there is no marker[2] ...

I would suggest using function closure and a createMarker function to
associate the infowindow content and click handler with the marker.

  -- Larry


>                         infowindow2.open(map,marker[i]);
>                 }); (map,popuphtml,marker,newpoints);
>
>         }
>
>
>
> }

-- 
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 [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-js-api-v3?hl=en.

Reply via email to