I’ve been searching all over trying to find simple code to add multiple markers to Google Maps. I’ve adjusted code to the simple marker example in hopes that it would work. I don’t get any errors from the php code, so I am guessing the map code is screwed up. Here is the code I have so far:
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(<? echo $latlonlocation; ?>);
var myOptions = {
zoom: <? echo $zoom; ?>,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
var circle = new google.maps.Circle({
map: map,
radius: <? echo $searchradius; ?>
});
circle.bindTo('center', marker, 'position');
<?
$mapcounter = "01";
while ($row106 = mysql_fetch_array($r106)) {
if ($row106["mna"] == 1 && $row106["mrt"] == 1) {
$imagecolor = "yellow";
} elseif ($row106["mna"] == 1 && $row106["mrt"] == 0) {
$imagecolor = "darkblue";
} elseif ($row106["mna"] == 0 && $row106["mrt"] == 0) {
$imagecolor = "red";
} else {
$imagecolor = "red";
}
$imagenumber = sprintf("%02d",$mapcounter);
echo "var image = 'mapicons/$imagecolor$imagenumber.png';";
echo "var DealerMarker$imagenumber = new google.maps.Marker({";
$lats = $row106["latitude"];
$lons = $row106["longitude"];
echo "position: $lats $lons,";
echo "map: map,";
echo "icon: image";
$mapcounter++;
echo "});";
}
?>
google.maps.event.addDomListener(window, 'load', initialize);
</script>
I’ve also tried modifying the }); at the end to have it either inside or outside the array loop. Neither has worked. The exact code worked with static variables before I added the array loop to it. Can anyone get me going in the right direction
try replacing
echo "position: $lats $lons,";with
echo "position: new google.maps.LatLng($lats, $lons),"