gpt4 book ai didi

javascript - 为什么谷歌地图不显示在我的网站上,我一直在使用开发者网站?

转载 作者:行者123 更新时间:2023-11-28 06:16:54 27 4
gpt4 key购买 nike

/* This is the javascript function that makes the map load */
function initMap() {
var mapDiv = document.getElementById('map');
var map = new google.maps.Map(mapDiv, {
center: {
lat: 44.540,
lng: -78.546
},
zoom: 8
});
}
/* This is the basic css */

#map {
width: 500px;
height: 400px;
}
<!-- Javascript called into the html page -->

<!DOCTYPE html>
<html>
<head>
</head>

<body>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js" async defer></script>
</body>

</html>

最佳答案

你的函数没有调用 use $(document).ready(function()()) 来调用你的函数

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
$(document).ready(function() {
var mapDiv = document.getElementById('map');
var map = new google.maps.Map(mapDiv, {
center: {lat: 44.540, lng: -78.546},
zoom: 8
});

});
</script>
<style>
#map {
width: 500px;
height: 400px;
}
</style>
</head>
<body>
<div id="map"></div>

</body>
</html>

关于javascript - 为什么谷歌地图不显示在我的网站上,我一直在使用开发者网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35842216/

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