Google 地图显示所有标记的相同信息 window
Google maps showing same info window for all markers
我正在遍历属性数组并在 google 地图上创建多个标记。我希望这些标记中的每一个都有自己的信息 window 内容。我的代码在我看来是正确的,但它不起作用。有人能给我指出正确的方向吗?
这是我当前的代码
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);
试试这个方法:
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);
我正在遍历属性数组并在 google 地图上创建多个标记。我希望这些标记中的每一个都有自己的信息 window 内容。我的代码在我看来是正确的,但它不起作用。有人能给我指出正确的方向吗?
这是我当前的代码
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);
试试这个方法:
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);