gpt4 book ai didi

javascript - 载入谷歌地图

转载 作者:行者123 更新时间:2023-11-30 06:00:28 24 4
gpt4 key购买 nike

我试图在我的 Javascript 中加载 Google map ,但我一直收到错误“document.body is null”。有人可以帮忙吗?

<html>

<head>

</head>

<body>

<div></div>

</body>

</html>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="https://www.google.com/jsapi?key=gfgfgfgfgfg"></script>


<script type="text/javascript">

$(document).ready(function () {

google.load('maps','3', {other_params: "sensor=false&callback=mapsLoaded&key=gfgfgfgfgf"});


});

function mapsLoaded()
{
alert("done");
}

</script>

最佳答案

对于 API 的第 3 版,您应该尝试不同的方法:

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=drawing"></script>
<script type="text/javascript">
$(document).ready(function () {
var myOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
});
</script>
</head>
<body>
<div id='map_canvas' style="width:450px; height:450px"></div>
</body>
</html>

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

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