Map isn't showing on Google Maps JavaScript API v3 when nested in a div tag
Add style="width:100%; height:100%;"
to the div see what that does
not to the #map_canvas
but the main div
example
<body>
<div style="height:100%; width:100%;">
<div id="map-canvas"></div>
</div>
</body>
There are some other answers on here the explain why this is necessary
Cannot generate Google Map
I don't know why but yes, when i try to check your code i found that you didn't add css of body and html given by google map. When i add that it shows content inside it. CSS code i found is below-
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
Please check and respond
Google Maps div not showing up in JSBin
Use can use absolute positioning without a width | height
value, using top|left|bottom|right
with 0
set as their values which would result in the #map-canvas
div
becoming the size of the containing element #second
as long as it is set to relative like so:
#second {
position: relative;
}
#map-canvas {
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
}
Here is the updated bin.
I hope this helps!
Google map inside multiple divs not showing
Update:
Strangely enough, I've made it work by referencing all my CSS and JavaScript codes on the <head>
of my webpage (the CSS codes were referenced on the <head>
but the JavaScript codes were referenced before the </body>
).
I am not sure if which of my JavaScript codes influenced Google Map to act like that, but well, if it's working then it ain't stupid!
My map is created but can not be displayed
Make sure you have changed your CSS class name to map1
#map1 {
height: 300px;
width: 600px;
background-color: #CCC;
}
working code with map1 as id in css file Jsfiddle
Related Topics
How to Access Accelerometer/Gyroscope Data from JavaScript
Get Element's CSS Selector (When It Doesn't Have an Id)
How to Prevent Simultaneous Logins of the Same User with Firebase
How to Display Binary Data as Image - Extjs 4
How to Support Promises in Internet Explorer 11
Use Jquery to Scroll to the Bottom of a Div with Lots of Text
Chrome Extension: Get Page Variables in Content Script
Sort Object Properties and JSON.Stringify
How Do the JavaScript Relational Comparison Operators Coerce Types
Is Performing a Mapping Operation Without Using Returned Value an Antipattern
Advanced JavaScript: Why Is This Function Wrapped in Parentheses
Get Function Name in JavaScript
Wrapping Lines/Polygons Across the Antimeridian in Leaflet.Js
Prevent Automatic Browser Scroll on Refresh
Is It a Good Idea to Learn JavaScript Before Learning Jquery