Thanks Rossko. Yes, that's done the trick. I knew it was something
like that. For the edification of anyone with a similar challenge,
here is the working code. Thanks again.
<script type="text/javascript">
var map;
var markers = new Array();
bounds.extend(myLocations[i]);
map.fitBounds(bounds);
attachInfo(markers[i], i); // call function outside of loop
} // end for loop
function attachInfo(marker, number) {
var infowindow = new google.maps.InfoWindow(
{ content: myContent[number]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} // end attachInfo
} // end initialize
On Jun 1, 4:28 pm, Rossko <
ros...@culzean.clara.co.uk> wrote:
> > var ContentID = myContent[i];
>
> > google.maps.event.addListener(markers[i], 'click',
> > function() {
> > info.setContent(ContentID);
>
> You're not getting closure on ContentID. When the loop finishes,
> ContentID is set to the last item. Later, when any of the click
> listeners are triggered, they all use the same ContentID.
>
> See this examplehttp://
code.google.com/apis/maps/documentation/javascript/examples/ev...