请帮我调试Chrome不认识谷歌的原因。 我得到这个错误:
未捕获的引用错误谷歌未定义
Uncaught ReferenceError: google is not defined
我提出API脚本顶部,失败。 我调整了自己的代码以匹配Google的文档,失败。 Chrome是否会导致我的问题?
<!DOCTYPE html>
<html>
<head>
<title>weather map</title>
<style type="text/css">
html, body {
margin: 0;
}
#map-canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container">
<h1>Map Test</h1>
<div id="map-canvas">
</div>
</div>
<script type="text/javascript" src="/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
google.maps.event.addDomListener(window, 'load', initMap);
});
var map;
function initMap() {
map = new google.maps.Map(document.getElementById("map- canvas"), {
center: {lat: 29.423017, lng: -98.48527},
zoom: 8,
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=MY_KEY_WAS_HERE_&callback=initMap">
</script>
</body>
</html>
控制台是否告诉你哪行代码引起了引用错误? –
尝试从脚本标记中删除“延迟”。延迟阻止脚本标记执行,直到DOM被解析。由于你的$(document).ready函数出现在脚本标记之前,它首先尝试执行。或者,将$(document).ready函数上方的maps.googleapis的脚本标记移动。 –
Vincent,它说这行是问题:
google.maps.event.addDomListener(window,'load',initMap); – Paula