-1

I am using google map with API.

I am running it on a responsive website. The issue i am having is when i apply width: 100% to it, it goes blank. I tried by warping it in outer div but still no luck.

I've read other Stack questions but did't find any working solution for this.

HTML

<div id="mapCanvas" class="mapCanvas"></div>

CSS

       .mapCanvas{
        width: 800px; /* When i set it to 100%, Map goes BLANK */
        height: 200px;
        }


        .mapContainer
        {
        display:inline-block;
        }
        .mapContainer div, .mapContainer ul
        {
        float:left;
        }
        .infoWindow h1 {
        font-size: 1.6em;
        text-align: center;
        padding-bottom: 1px;
        }
        .infoWindow {
        overflow: hidden;
        }

JS

markers = [];
function initialize() {
var mapOptions = {
  center: new google.maps.LatLng(51.061150138439515, -114.05261809049074),
  zoom: 14,
  mapTypeId: google.maps.MapTypeId.ROADTYPE,
  panControl: false,
  zoomControl: false,
  mapTypeControl: false,
  scaleControl: false,
  streetViewControl: false
};
map = new google.maps.Map(document.getElementById("mapCanvas"),mapOptions);

var marker0 = new google.maps.Marker({
    position: new google.maps.LatLng (51.063838646941576,-114.05572414398193),
    map: map,
    icon: "http://www.earthpoint.us/Dots/GoogleEarth/paddle/ylw-blank.png"
});
markers.push(marker0);
var infowindow0 = new google.maps.InfoWindow({
    content: "<div class='infoWindow'><h1> We are here </h1></div>",maxWidth: 350
});
google.maps.event.addListener(marker0, "click", function()
{
    infowindow0.open(map,marker0);
});

  }
  google.maps.event.addDomListener(window, "load", initialize);

Can anyone help?

YOU
  • 1,030
  • 1
  • 7
  • 22

2 Answers2

1

Set a width to the container for this div, and add the following styles too;

.mapCanvas{
        max-width: 800px; 
        height: 200px;
        width: 100%;
        }

This css will ensure the mapCanvas div does not exceed 800px; but also will ensure it stays at 100% width of the containing div, therefore as the window (device) decreases in width so will the map.

Jay
  • 772
  • 1
  • 6
  • 17
0

You need to specify the size (height and width) of any parent elements up to html & body.

working fiddle

html, body {
    height: 100%;
    width: 100%;
}
.mapCanvas {
           width: 100%;
           height: 100%;
}
geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Sorry For bothering you! It was an issue due to outer div becuase it was set to height only, not to width. that's why map was going blank. I am not sure which answer to accept, So, If you vote up my question then i will accept yours :) – YOU Aug 12 '14 at 15:55
  • It is a duplicate then. – geocodezip Aug 12 '14 at 16:13