gpt4 book ai didi

javascript - 谷歌地图无法加载

转载 作者:行者123 更新时间:2023-11-28 04:46:08 24 4
gpt4 key购买 nike

在调整浏览器窗口大小之前, map 不会在我的网站上加载

这是我的 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>

这是 CSS

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

当我删除 .map-cont { margin-left: 10%; } 它工作正常,但我不需要全屏显示。

最佳答案

我会尝试调整 css 并包含这些行。

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

谷歌地图 API 想要明确定义 map 的高度和宽度,有时这可能会导致复杂化。

关于javascript - 谷歌地图无法加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43350852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com