简体   繁体   English

Google地图无法加载

[英]Google map won't load

Map wont load on my website 'till browser window is resized 地图不会加载到我的网站上,直到调整浏览器窗口大小

Here is my JS code 这是我的JS代码

<div class="map-cont">
        <div id="map" class="location-container map-padding" style="width:100%;height:400px;background:yellow"></div>
          <script>
          function initMap() {
            var uluru = {lat: 45.4420432, lng: 15.999982};
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 15,
              center: uluru,
              scrollwheel: false
            });
            var marker = new google.maps.Marker({
              position: uluru,
              map: map
            });
          }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBEQc2mBnThiUz-Pj472iG1i2FyqJvNb00&callback=initMap">
        </script>
    </div>

And here is CSS 这是CSS

#map { width: 100% !important; }
.map-cont { margin-left: 10%; }

When I remove .map-cont { margin-left: 10%; } 当我删除.map-cont { margin-left: 10%; } .map-cont { margin-left: 10%; } it works fine, but I don't need it fullscreen. .map-cont { margin-left: 10%; }它工作正常,但我并不需要它全屏。

I would try adjusting the css and include these lines lines. 我会尝试调整css并包含这些线条。

   #map {
    width: 100%;
    height: 100%;
   }
   html,body{
     height: 100%;
     margin:0px;
   }

The google maps api wants to explicitly define the height and width of the map, and at times this can cause complications. 谷歌地图api想要明确定义地图的高度和宽度,有时这会导致复杂化。

The problem with the sizing issue was that the 尺寸问题的问题在于

      style="width:100%;height:400px;background:yellow"></div>
      <script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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