javascript - Google Maps generates blank grey <div> -
i trying generate several google map elements on single page inside jquery each()
function. there several .new-venue-item
elements on page, , 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 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 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>
and jquery code is:
$('.new-venue-item').each(function() { var $map = $(this).find('.map'), lat = parsefloat($map.data('lat')), lng = parsefloat($map.data('lng')); // hook 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)); });
unfortunately, generates blank map element grey background. there no errors in console, , map api being correctly included. has encountered issue before, , how might fix it?
i have put jsfiddle demonstrating problem.
in example zoomlevel
needs changed zoom
fixes issue.
$('.new-venue-item').each(function() { var $map = $(this).find('.map'), lat = parsefloat($map.data('lat')), lng = parsefloat($map.data('lng')); // hook map: var mapoptions = { scrollwheel: false, streetviewcontrol: false, maptypecontrol: false, pancontrol: false, zoomcontrol: false, draggable: false, zoom: 14, //changed zoomlevel center: { lat: lat, lng: lng } }; //new google.maps.map( document.getelementbyid('map8160'), mapoptions ); $(this).data('map', new google.maps.map($map[0], mapoptions)); });
it took me while figure out
Comments
Post a Comment