【问题标题】:Google Maps API Is Not Loading Properly [duplicate]Google Maps API 未正确加载 [重复]
【发布时间】:2019-07-08 20:50:36
【问题描述】:

我的代码和加载带有样式的嵌入式 Google Maps API 时遇到问题。请参阅下面的代码以及加载网页时发生的屏幕截图。

<section class="container-fluid text-center">
        <div class="row">
             <div class="col">
                <div id="map" style="height: 100%;
            width: 750px;"></div>
            </div>
        </div>
    </section>


            <script>
                function initMap(){
                    var latlng = { lat:40.589493, lng:-75.603426 };
                var map = new google.maps.Map(document.getElementById('map', {
                    center: latlng,
                        zoom: 8,

                }));
                var marker = new google.maps.Marker({
                    position: latlng,
                    map: map
                });
                marker.addListener('click', function() {
                        infowindow.open(map, marker);
                    });
                }
            </script>

            <script async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap"></script>

https://i.stack.imgur.com/TqthU.png

【问题讨论】:

  • 控制台有错误吗?
  • 没有。只有当我双击地图时,我才会在控制台中收到以下错误: Uncaught TypeError: Cannot read property 'zoom' of null at Object.onClick (map.js:11) at HTMLDivElement.Wm.F._.Dm .Pa(common.js:63) onClick@map.js:11 Wm.F._.Dm.Pa@common.js:63

标签: javascript html google-maps-api-3


【解决方案1】:

确保您的地图 div 具有适当的高度和宽度

<div class="col">
    <div id="map" style='width: 400px; height: 400px;'></div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 2013-03-19
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    • 2018-09-02
    相关资源
    最近更新 更多