-1
は
index.htmlファイルのプロパティ「マップ」を読み取ることができませんされています:
<!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>
スクリプト.jsファイルは次のとおりです。
(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));
CSSファイルは次のとおりです。
html {
height: 100%;
}
body {
height:100%;
padding: 0;
margin: 0;
}
#map-canvas {
height: 100%;
}
async deferを削除しても地図が表示されない –
'&callback ='を削除し、onload関数を追加して 'initMap'関数を実行する必要があります。 – geocodezip