How to get a google map to use 100% of its parent container?

23,996

Google says:

Unless you specify a size explicitly for the map using GMapOptions in the constructor, the map implicitly uses the size of the container to size itself.

So set the size of your map container fill all available space:

<div id="map2" style="width: 100%; height: 100%"></div>
Share:
23,996
Artilheiro
Author by

Artilheiro

Updated on January 13, 2020

Comments

  • Artilheiro
    Artilheiro over 4 years

    I have tried to do this in many different ways but the most obvious was this:

    var map2 = new GMap2(document.getElementById("map2"), {size:"100%"});
    

    That does not work.

  • Alex
    Alex over 14 years
    You don't event need to add the width css property. Because "div" is naturally a block level element it will fill to it's parent's width :) Good answer though!
  • Artilheiro
    Artilheiro over 14 years
    I am doing that today using jQuery. It works for the most part but if the user resizes the window the map does not resize with it.
  • Artilheiro
    Artilheiro over 14 years
    Perfect! I was trying to use GSize which would not take a percentage.
  • Elshan
    Elshan almost 6 years
    added position: relative; with above and works fine.