I am using [this][1] tutorial to render google map on my webpage. It works fine when I use it in the way it's in this tutorial. But it doesn't render on my webpage.
I have a tabbed webpage. Each tab content is opened with a div containing its id. So when I put the div with the id of map which is used by render map function to render map, it's inside the div of a Live Map tab. And it's not working.
Here is my code:
Tabbed HTML on my webpage:
<div class="tab"> //tabs defined
<button class="tablinks" onclick="openCity(event, 'tab1')">tab1</button>
<button class="tablinks" onclick="openCity(event, 'tab2')">tab2</button>
<button class="tablinks" onclick="openCity(event, 'Live-Map')">Live Map</button>
</div>
<div id="Live-Map" class="tabcontent"> //map div inside tab div
<div id="map"></div> //map div
</div>
<script> // tab selector js function
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
EDIT
CSS
This is css. Trying solutions from other sources, I found the height of the parent div needs to be made 100%. I did that too but still no success.
#map {
height: 100%;
}
#Live-Map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
EDIT
I solved the problem with bit search. The problem basically was have to give the wrapper div also 100% height & width and also to the bootstrap container div. Because Google API requires these parameters to render,
#Live-Map, #map {
height: 100%;
width: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
<div style="Height:100%; Width:100%;" class="container-fluid">