Google地图会生成空白的灰色< div> [英] Google Maps generates blank grey <div>

查看:66
本文介绍了Google地图会生成空白的灰色< div>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在jQuery each()函数内的单个页面上生成多个Google Map元素.页面上有几个 .new-venue-item 元素,它们看起来像这样:

I am currently trying to generate several Google Map elements on a single page inside a jQuery each() function. There are several .new-venue-item elements on the page, and they look like this:

<div class="new-venue-item">
   <div class="image">
      <div class="image">
         <a href="/venue/8121_the-square-bristol-city-of-bristol" title="Discover more about The Square"><img src="http://static.weddingvenues.com/venues/200x300/Wedding-image-with-logo-rectangular.jpg" class="" width="200" height="300" alt="" title="" item-prop=""></a>
      </div>
      <div id="map8121" class="map" data-lng="-2.6101986" data-lat="51.4590031">
      </div>
      <div class="overlay">
         <a href="#" class="action-btn btn-wv contact-venue trackit" data-click-type="search-contact" data-venue-id="8121" data-customer-id="4038" data-id="8121">Contact venue</a>
         <a href="/venue/8121_the-square-bristol-city-of-bristol/" class="action-btn btn-white trackit" data-click-type="search-map" data-venue-id="8121" data-customer-id="4038">More info</a>
      </div>
   </div>
   <div class="info">
      <a href="/venue/8121_the-square-bristol-city-of-bristol" title="Discover more about The Square">The Square</a>
      <span class="address"><span class="address"><a href="/p-544/united-kingdom/england/city-of-bristol/bristol/" title="Bristol, City of Bristol">Bristol</a>, <a href="/p-164/united-kingdom/england/city-of-bristol/" title="City of Bristol, England">City of Bristol</a></span></span>
   </div>
</div>

然后jQuery代码是:

And then the jQuery code is:

$('.new-venue-item').each(function() {

    var $map = $(this).find('.map'),
        lat = parseFloat($map.data('lat')),
        lng = parseFloat($map.data('lng'));

    // Hook up the map:
    var mapOptions = {
        scrollwheel: false,
        streetViewControl: false,
        mapTypeControl: false,
        panControl: false,
        zoomControl: false,
        draggable: false,
        zoomLevel: 14,
        center: {
            lat: lat,
            lng: lng
        }
    };

    //new google.maps.Map( document.getElementById('map8160'), mapOptions );

    $(this).data('map', new google.maps.Map($map[0], mapOptions));


});

不幸的是,这会生成带有灰色背景的空白地图元素.控制台中没有错误,并且正确包含了Map API.以前有没有人遇到过这个问题,我该如何解决?

Unfortunately, this generates a blank map element with a grey background. There are no errors in the console, and the Map API is being correctly included. Has anyone encountered this issue before, and how might I fix it?

我整理了一个 jsFiddle 来说明问题.

I have put together a jsFiddle demonstrating the problem.

推荐答案

在您的示例中,需要将 zoomLevel 更改为 zoom ,以解决此问题.

In your example zoomLevel needs to be changed to zoom which fixes the issue.

$('.new-venue-item').each(function() {

    var $map = $(this).find('.map'),
        lat = parseFloat($map.data('lat')),
        lng = parseFloat($map.data('lng'));

    // Hook up the map:
    var mapOptions = {
        scrollwheel: false,
        streetViewControl: false,
        mapTypeControl: false,
        panControl: false,
        zoomControl: false,
        draggable: false,
        zoom: 14, //Changed from zoomLevel
        center: {
            lat: lat,
            lng: lng
        }
    };

    //new google.maps.Map( document.getElementById('map8160'), mapOptions );

    $(this).data('map', new google.maps.Map($map[0], mapOptions));

});

我花了一段时间才弄清楚

这篇关于Google地图会生成空白的灰色&lt; div&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆