-1

I'm looping over an array of properties and create multiple markers on a google map. I'd like each of these markers to have their own info window content. My code looks right to me but it's not working. Can somebody point me in the right direction.

Here is my current code

for (var i = startRow; i < AMdata.property.length; i++) {
                var propertyDetails = AMdata.property[i];
                var latLng = new google.maps.LatLng(propertyDetails.LATITUDE, propertyDetails.LONGITUDE);
                bounds.extend(latLng);
                var marker = new google.maps.Marker({
                    position: latLng,
                    title: propertyDetails.NAME,
                    icon: outIcon
                });

                // add an event listener for this marker
                google.maps.event.addListener(marker , 'click', function() {
                    // assuming you have some content in a field called Field123
                    infowindow.setContent('<div class="infowindow"><div class="panel-image listing-img"><img style="max-height:115px;" width="100%" src="' + propertyDetails.THUMBNAIL + '"></div><a href="' + propertyDetails.INTERNALURL + '"><p>' + propertyDetails.NAME + '</p></a></div>');
                    infowindow.open(map, this);
                });

                markers.push(marker);
            }

 var markerCluster = new MarkerClusterer(map, markers);
            map.fitBounds(bounds);
James Privett
  • 1,079
  • 3
  • 15
  • 23
  • possible duplicate of [Google Maps JS API v3 - Simple Multiple Marker Example](http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example) – geocodezip Jul 08 '15 at 14:26

1 Answers1

0

try this way :

for (var i = startRow; i < AMdata.property.length; i++) {
                var propertyDetails = AMdata.property[i];
                var latLng = new google.maps.LatLng(propertyDetails.LATITUDE, propertyDetails.LONGITUDE);
                bounds.extend(latLng);
                var marker = new google.maps.Marker({
                    position: latLng,
                    title: propertyDetails.NAME,
                    icon: outIcon
                });

                // add an event listener for this marker

               k =  markers.push(marker);

                google.maps.event.addListener(markers[k-1] , 'click', function(propertyDetail) {
                    // assuming you have some content in a field called Field123
                    infowindow.setContent('<div class="infowindow"><div class="panel-image listing-img"><img style="max-height:115px;" width="100%" src="' + propertyDetails.THUMBNAIL + '"></div><a href="' + propertyDetails.INTERNALURL + '"><p>' + propertyDetails.NAME + '</p></a></div>');
                    infowindow.open(map, this);
                });
            }

 var markerCluster = new MarkerClusterer(map, markers);
            map.fitBounds(bounds);
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107