Google地图显示所有标记

时间:2015-07-08 13:34:19

标签: google-maps infowindow marker

我循环遍历一组属性并在Google地图上创建多个标记。我希望每个标记都有自己的信息窗口内容。我的代码看起来正确,但它不起作用。有人能指出我正确的方向。

这是我目前的代码

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);

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

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);