简体   繁体   中英

Initializing Javascript Google Maps issue

I am having an issue initializing a map in the page. The code within my body tags is shown below:

<body>
      <div class="outer">
            <div class="header">
            </div>
            <div class="main">
                  <div id="map_canvas">
                  </div>
            </div>
            <div class="footer">
            </div>
              </div>
</body>

When I initialise the function on the main class, the map displays properly.

var map = new google.maps.Map(document.getElementById("main"), myOptions);

However when the map is initialised as shown below, it does not display at all on the page.

var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

I am not sure what is causing this or how to fix it. Any help is greatly appreciated.

您的map_canvas div需要将其id设置为“ map_canvas”,同时还要确保map_canvas div的css设置为具有宽度和高度。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM