Google地图不会加载

时间:2018-11-27 16:36:08

标签: javascript

我将WP Google Maps Pro插件用于Wordpress网站。我要做的是隐藏此地图,直到单击缩略图。

因此,这是我的整个脚本:

<div class="c-map">
  <div id="e-map" class="e-mapThumbnail">
    <div class="e-yt_video-icon">
      <i class="fab fa-youtube"></i>
      <span>click to show video</span>
      <div>
      </div>
    </div>
    <script>
      jQuery(document).ready(function($) {
        $(document).ready(function($) {
          $('.e-mapThumbnail ').click(function() {
            var map = `<div class="map"><?php echo do_shortcode('[wpgmza id="3"]'); ?></div>`;
            $('#e-map').html(map);
          });
          $('.e-mapButton').click(function() {
            $('.e-mapThumbnail ').click();
          });
        });
      });
    </script>
  </div>
</div>
</div>

但未加载地图,并且在控制台中,我看到:

enter image description here

Uncaught TypeError: Cannot read property 'firstChild' of undefined
    at Object._.re (js?v=3.exp&language=pl&key=AIzaSyBaYYvw2wvFNRg4bT_juQO-8Jil21BvxKw&libraries=geometry%2Cplaces%2Cvisualization&ver=4.9.8:95)
    at new Qg (js?v=3.exp&language=pl&key=AIzaSyBaYYvw2wvFNRg4bT_juQO-8Jil21BvxKw&libraries=geometry%2Cplaces%2Cvisualization&ver=4.9.8:134)
    at Object.MYMAP.(:8888/icare/pl/dla-firm/anonymous function).init (http://localhost:8888/icare/wp-content/plugins/wp-google-maps-pro/js/core.js?ver=6.32p:1321:20)
    at InitMap (core.js?ver=6.32p:115)
    at HTMLDocument.<anonymous> (core.js?ver=6.32p:1156)
    at j (jquery-1.11.3.min.js?ver=1.11.3:2)
    at Object.fireWith [as resolveWith] (jquery-1.11.3.min.js?ver=1.11.3:2)
    at Function.ready (jquery-1.11.3.min.js?ver=1.11.3:2)
    at HTMLDocument.J (jquery-1.11.3.min.js?ver=1.11.3:2)

不幸的是,它超越了我的JS技术...所以任何人都可以给我任何线索吗?

1 个答案:

答案 0 :(得分:1)

仅当容器确实存在时,Google API才会呈现对象。 如果您在运行HTML时不在html中,则页面首次准备就绪时会出现异常。有帮助吗?