0

Am playing with Google Maps V3 API and StyledMarkers. The data is derived from a PHP/MySQL query returning several hundred points.

The code below returns everything I need and works fine EXCEPT for getting it to zoom to an approriate level (which in this case I know is 10).

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title><?php echo returnval("event_name","events",$_GET['eid']); ?> Map - No Refresh</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="StyledMarker.js"></script>
<script type="text/javascript">
function initialize() {
  var myLatLng = new google.maps.LatLng(<?php echo $evlat; ?>, <?php echo $evlng; ?>);
  var bounds = new google.maps.LatLngBounds();
  var myOptions = {
    zoom: 9,
    center: myLatLng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("show_map"), myOptions);
<?php
  $iconcntr = 0;
  while ($row = mysql_fetch_array($result)) {
    $iconcntr ++;
    $rfa_no = $row['rfa_no'];
    $longitude = $row['longitude'];
    $latitude = $row['latitude'];
    if ($row['rfa_priority'] == 1) {
      $iconclr = "FF0000";
    } elseif ($row['rfa_priority'] == 2) {
      $iconclr = "FFFF00";
    } else {
      $iconclr = "FFFFFF";
    }
?>
    var varLatLng = new google.maps.LatLng(<?php echo $latitude; ?>,<?php echo $longitude; ?>);
    bounds.extend(varLatLng);
    var styleMaker<?php echo $iconcntr; ?> = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.BUBBLE,{color:"<?php echo $iconclr; ?>",text:"<?php echo $rfa_no; ?>"}),position:new google.maps.LatLng('<?php echo $latitude; ?>', '<?php echo $longitude; ?>'),flat:true,zIndex:<?php echo ($iconcntr+1000); ?>,map:map});
<?php
  }
?>
  map.fitbounds(bounds);
}
</script>

</head />
<body style="margin:0px; padding:0px;" onload="initialize()" />
<div id="show_map" style="width:100%; height:100%;"></div>
</body>
</html>

Anyone have any idea what I'm doing wrong? Not very strong in the programming department.

tastech
  • 29
  • 6

1 Answers1

1

JavaScript is case-sensitive.

Use map.fitBounds(bounds) instead of map.fitbounds(bounds). Documentation

You should have seen an error in the Javascript Console about fitbounds not being a valid method or something similar.

Andrew Leach
  • 12,945
  • 1
  • 40
  • 47