-1
我正在设置不同机场位置的地图。我的标记位于正确的位置。Google Maps APIv3多个标记/多个信息窗口
我一直在尝试添加infowindows,但是每个InfoWindow都显示了数组中最后一个标记的相同内容。
我该如何解决这个问题,让每个标记都有自己独特的信息?
`setMarkers(map, airports);
}
function setMarkers(map, locations) {
for (var i = 0; i < locations.length; i++) {
var airport = locations[i];
var myLatLng = new google.maps.LatLng(airport[1], airport[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
html: airport[3],
});
var contentString =
<?php
$num_rows = (count($locations) - 1);
for($i = 0; $i < count($locations); $i++){
$query = "SELECT * FROM airports WHERE ident='$locations[$i]'";
$result = mysql_query($query, $link)
or die('Error querying database.');
while ($row = mysql_fetch_array($result)) {
if ($i == $num_rows){
echo "'<div id=\"content\">'+";
echo "'<div id=\"siteNotice\">'+";
echo "'</div>'+";
echo "'<b>" . $row['ident'] . "</b></br>'+";
echo "'" . $row['latitude_deg'] . ", " . $row['longitude_deg'] . "' +";
echo "'</div>'+";
echo "'</div>';";
}
}
}
?>
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
//infowindow.setContent(this.html);
infowindow.open(map,this);
});
}
}