Google地图会生成空白的灰色<div>

时间:2016-01-07 15:36:13

标签: javascript jquery google-maps

我目前正在尝试在jQuery UPDATE order_items o SET DISCOUNT_AMOUNT = (SELECT T.maxdiscount FROM (SELECT customer_id, o.order_id AS order_id, D.product_id AS product_id, D.total, E.maxdiscount AS maxdiscount FROM orders o, ( SELECT SUM (quantity) AS total, order_id, product_id FROM order_items GROUP BY order_id, product_id) D, ( SELECT MAX (discount_amount) AS maxdiscount, product_id FROM order_items GROUP BY product_id) E WHERE o.order_id = D.order_id AND E.product_id = D.product_id) T WHERE T.order_id = o.order_id AND T.product_id = o.product_id); 函数内的单个页面上生成多个Google Map元素。页面上有几个each()元素,它们看起来像这样:

.new-venue-item

然后jQuery代码是:

<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>

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

我已经整理了jsFiddle来证明这个问题。

1 个答案:

答案 0 :(得分:3)

在您的示例中,zoomLevel需要更改为zoom才能解决问题。

$('.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));

});

我花了一段时间才弄明白