Google地图V3,地图在封装到第二个div时不会显示 [英] Google Maps V3, Map won't display when wrapped in a second div

查看:102
本文介绍了Google地图V3,地图在封装到第二个div时不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google地图的新手。

 < body onload =initialize()我已经开始使用他们的Hello World代码了。 > 
< div id =map_canvasstyle =width:100%; height:100%>< / div>
< / body>

这当然可以正常工作。但是,如果我想将他们的div包装在另一个div中(这样我可以设置各种容器样式),地图根本不显示:

 < body onload =initialize()> 
< div>
< div id =map_canvasstyle =width:100%; height:100%>< / div>
< / div>
< / body>


解决方案

应用 width height div

 < div style =width:100%; height:100%;> 
< div id =map_canvasstyle =width:100%; height:100%>< / div>
< / div>

内部div( id =map_canvas格)大小由百分比设置。这意味着内部 div 将适合其父代大小。

I am a newbie to Google Maps. I have started with their "Hello World" code, which has the following:

<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>

which of course works fine. But, if I want to wrap their div in another div (so I can set various container styles), the map doesn't display at all:

<body onload="initialize()">
<div>
<div id="map_canvas" style="width:100%; height:100%"></div>
</div>
</body>

解决方案

Apply width and height to div:

<div style="width:100%; height:100%;">
   <div id="map_canvas" style="width:100%; height:100%"></div>
</div>

Inner div's ( id="map_canvas" div ) sizes are set by percents. This means inner div will be fit to its parent sizes.

这篇关于Google地图V3,地图在封装到第二个div时不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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