制作div内容(googlemap)全屏

时间:2010-05-21 19:25:28

标签: javascript google-maps

我试图制作一个按钮,将googlemap div变为全屏.. 这是我现在直到现在,但它没有正常工作.. 问题是: 地图只会加载一半 代码如下,以及截图

我该怎么修呢?问题出在哪儿? 提前谢谢

http://img32.imageshack.us/img32/9365/halfload.gif

<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
  function initialize() { 
    var latlng = new google.maps.LatLng(-34.397, 150.644); 
    var myOptions = { 
      zoom: 8, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
  } 

function fs() {
    var elem = document.getElementById("map_canvas");
 elem.style.position="absolute";
 elem.style.width="100%";
 elem.style.height="100%";
 elem.style.top="0px";
 document.body.style.overflow = "hidden";

}

</script> 
</head> 
<body onload="initialize()"> 
  <div id="map_canvas" style="width:400px; height:300px"></div> 
  <a href="#" onclick ="fs()">makefullscreen</a>
</body> 
</html>

1 个答案:

答案 0 :(得分:1)

你需要在地图最大化后重新初始化地图...这是代码:

<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
  function initialize() { 
    var latlng = new google.maps.LatLng(-34.397, 150.644); 
    var myOptions = { 
      zoom: 8, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
  } 

function fs() {
    var elem = document.getElementById("map_canvas");
 elem.style.position="absolute";
 elem.style.width="100%";
 elem.style.height="100%";
 elem.style.top="0px";
 document.body.style.overflow = "hidden";

}

</script> 
</head> 
<body onload="initialize()"> 
  <div id="map_canvas" style="width:400px; height:300px"></div> 
  <a href="#" onclick ="fs(); initialize();">makefullscreen</a>
</body> 
</html>

希望这有助于, 大风