Javascript Google控制台中的未捕获类型错误
在创建一个基本的谷歌地图时,我遇到了以下错误:uncaughttypeerror:无法读取未定义的属性“maps” Index.html文件是:Javascript Google控制台中的未捕获类型错误,javascript,google-maps-api-3,Javascript,Google Maps Api 3,在创建一个基本的谷歌地图时,我遇到了以下错误:uncaughttypeerror:无法读取未定义的属性“maps” Index.html文件是: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <div id="map-canvas"></div> <sc
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="map-canvas"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBKNPX_2z_JDWcyADlzzFk9JChR4TwhZLQ"
async defer></script>
</script>
<script src="script.js"></script>
</body>
</html>
css文件是:
(function(window,google)
{
//maps options
var options={
center: {
lat:"0",
lng:"0"
},
zoom:0
},
//maps
element=document.getElementById('map-canvas'),
map = new google.maps.Map(element,options);
}(window,window.google));
html {
height: 100%;
}
body {
height:100%;
padding: 0;
margin: 0;
}
#map-canvas {
height: 100%;
}
错误告诉您,当您试图运行依赖于Google Maps Javascript API v3的代码时,该API v3未加载
您正在使用“async defer”加载Google Maps Javascript API v3,但是在内联加载您的脚本时,您需要延迟两者或在不使用“async defer”的情况下同时加载两者。即使在删除async defer之后,我也看不到映射。您必须删除
&回调=
,并添加一个onload函数来运行initMap
函数。