You are on page 1of 1

I'm trying to load multiple markers to my map using the following

code. It load the multiple markers just fine, but when I click on the
marker to provide info, it gives me the same text (the last text
loaded from the db query) into each InfoWindow! Anybody know how I can
improve my code to fix this? Thanks!
<code>
<script type="text/javascript">
// Creating a LatLng object containing the coordinate for the center
of the map
var latlng = new google.maps.LatLng(32.396989, -111.004427);
// Creating an object literal containing the properties we want to
pass to the map
var options = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Calling the constructor, thereby initializing the map
var map = new google.maps.Map(document.getElementById('map'),
options);
<?php
$link = mysql_connect("localhost", "<user>", "<password>") or
die("Could not connect: " . mysql_error());
mysql_selectdb("lightning",$link) or die ("Can\'t use dbmapserver :
" . mysql_error());
$result = mysql_query("SELECT * FROM shotspots",$link);
if (!$result)
{
echo "no results ";
}
while($row = mysql_fetch_array($result))
{
echo "var marker = new google.maps.Marker({\n";
echo " position : new google.maps.LatLng(" . $row['latitude'] .
"," . $row['longitude'] . "),\n";
echo " map : map,\n";
echo " icon : 'images/photo.png'\n";
echo "});\n";
echo "var infowindow = new google.maps.InfoWindow({\n";
echo " content : '" . addslashes($row['description']) . "'\n";
echo "})\n";
echo "google.maps.event.addListener(marker, 'click', function() {\n";
echo " infowindow.open(map, marker);\n";
echo "})\n";
}
mysql_close($link);
?>
</script>
</code>

You might also like