尝试使Google Maps Fitbound正常工作 [英] Trying to get Google Maps fitbounds to work

查看:63
本文介绍了尝试使Google Maps Fitbound正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在使用Google Maps V3 API和StyledMarkers.数据来自返回数百点的PHP/MySQL查询.

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

下面的代码返回我需要的所有内容,并且可以使它缩放到适当的水平(在这种情况下,我知道是10),可以正常工作.

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.

推荐答案

JavaScript区分大小写.

JavaScript is case-sensitive.

使用 map.fitBounds(bounds) 代替map.fitbounds(bounds). 文档

您应该已经在Javascript控制台中看到有关fitbounds不是有效方法或类似方法的错误.

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

这篇关于尝试使Google Maps Fitbound正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆