2012-06-16 13 views
0

正在玩Google Maps V3 API和StyledMarkers。数据来源于返回几百个点的PHP/MySQL查询。试图让Google地图fitbounds正常工作

下面的代码返回我需要的一切,并且工作正常,除了让它缩放到一个适当的级别(在这种情况下我知道是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> 

任何人有任何想法我做错了什么?编程部门不是很强大。

回答

1

JavaScript区分大小写。

使用map.fitBounds(bounds)而不是map.fitbounds(bounds)Documentation

您应该在Javascript Console中看到关于fitbounds不是有效的方法或类似的错误。

+0

呃!我一直在寻找它,我错过了这一点。干杯 – tastech