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