Sounds like the tab is displayed long before the map. You probably need to refresh the page after the map data is received.
Dec 17, 2016
5
Level 3
Google Map in Bootstrap Tabs
Hi All.
I try to display a Google map in a Bootstrap tab, but the map is not displayed.
Outside the tab the map is display correctly.
HTML :
<!-- MAP -->
<div class="tab-pane fade text-center" id="address">
{{ $ad->address }}
<br>
{{ $ad->zip }} {{ $ad->city }} - {{ $ad->country }}
<!-- MAP -->
<div id="map">
</div>
<!-- End ...MAP -->
</div>
<!-- End ... MAP -->
SCRIPT :
<script>
var initMap = function()
{
var map = new google.maps.Map( document.querySelector( '#map' ),
{
center : { lat : 35, lng : -85 },
zoom : 15
} );
var geocoder = new google.maps.Geocoder();
geocodeAddress( geocoder, map );
// ------------------------------------------------------------
function geocodeAddress( geocoder, resultsMap )
{
var address = '3 rue de la république 06000 Nice FR';
geocoder.geocode( { 'address': address }, function( results, status )
{
if( status === google.maps.GeocoderStatus.OK )
{
resultsMap.setCenter( results[0].geometry.location );
var marker = new google.maps.Marker(
{
map : resultsMap,
position : results[ 0 ].geometry.location
} );
}
else
{
alert( 'Geocode was not successful for the following reason : ' + status );
}
} );
}
};
</script>
Level 3
I used a trick, I move the map outside the screen, and when I click on the tab 5 I move the map to it's original postion :
JS :
$( document ).ready( function()
{
$( '#map' ).css( { 'position' : 'absolute', 'top' : '-9999px' } );
// ------------------------------------------------------------
$( '#tab_5' ).on( 'click', function()
{
$( '#map' ).css( { 'position' : 'relative', 'top' : '0' } );
} );
// ------------------------------------------------------------
$( '#tab_1, #tab_2, #tab_3, #tab_4' ).on( 'click', function()
{
$( '#map' ).css( { 'position' : 'absolute', 'top' : '-9999px' } );
} );
} );
Please or to participate in this conversation.