サイト内にGoogleマップの読み込んだ際にエラーが時々出ます。
基本的には正しく読み込んでくれるんですが、たまに読み込まない時があり、デベロッパーツールで見てみると
下記のようなエラーが出ています。
Uncaught (in promise) TypeError: Cannot read property 'firstChild' of null at Object._.re (js?key=A[APIキー]&callback=initMap:73) at new Qg (js?key=[APIキー]&callback=initMap:112) at initMap (index.js:3) at js?key=[APIキー]&callback=initMap:123 at js?key=[APIキー]&callback=initMap:123
html
1 <script src="./js/map.js"></script> 2 <script async defer src="https://maps.googleapis.com/maps/api/js?key=[APIキー]&callback=initMap"></script> 3 4ボディ内に 5 <div id="map"></div>
JS
1function initMap() { 2 var latlng = new google.maps.LatLng( XX.XXXXXX, XXX.XXXXXX ); 3 var map = new google.maps.Map(document.getElementById('map'), { 4 zoom: 17, 5 center: latlng 6 }); 7 8 var marker = new google.maps.Marker({ 9 position: latlng, 10 map: map, 11 icon: 'http://~~/img/mao_icon.png' 12 }); 13 } 14
CSS
1#map { 2 width: 100%; 3 height: 370px; 4}
調べてみたところ読み込みのタイミングのせいで起きるエラー?といった感じぽいのですが
いまいちよくわかりません…
どういった時このエラーが出るのか、解説を出来る方いましたらよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー