How to change size of infoWindow in Google Map with API

I ran into a problem the other day when trying to resize the ‘infoWindow’ on a Google Map. The infoWindow is the bubble that appears on the map, usually above a pin-marker when you click on it. Google’s own map has this behavior.

As usual, my solution requires some YUI components. I think you’ll just need the selector module and the core.

The problem I was running into, was that Google provides no way for the infoWindow to be resized. The easiest thing would have been for google to add CSS classes onto all the divs that make up the infoWindow but for some reason, they haven’t provided this and you need to jump through hoops if you really want to resize it. Typically, it seems that people would like to shrink the height because, for some reason, google will not resize it any lower than about 60px, even if the content is much small. In my case, I had only two lines in the infoWindow and a bunch of ugly whitespace below.

You can use the infoWindow.reset method, but the first three parameters are actually required despite what the API seems to imply.

“Resets the state of the info window. Each argument may be null and then
its value will not be changed from the current value.”

This is WRONG. Only the last two arguments are options, which you can tell by the ‘?’ in the method signature on the left.

“reset(latlng:GLatLng, tabs:GInfoWindowTab[], size:GSize, offset?:GSize, selectedTab?:Number)”

If you got this far, then perhaps you might have tried showing the infoWindow and then resetting it to the size you wanted, however, this will only work if you put your call to the reset method into the onOpenFn of the infoWindowOptions. It seems that when the info window is shown it is animated and then resized itself, so if you call the reset method directly after calling openInfoWindow it will animate and then resize AFTER your reset has already done your resizing… However, even this will not let you make the infoWindow’s height any smaller than about 60 px as I mentioned above, don’t worry though, we’ll get there!

Code to resize the infoWindow TALLER than 60px:

var infoWindow = map.getInfoWindow();
var point = new GLatLng(0,0);
var marker = new GMarker(point);
GEvent.bind(marker,”click”,marker,function() {
map.openInfoWindowHtml(this.getPoint(),this.address,{onOpenFn:function(){
infoWindow.reset(this.getPoint(),infoWindow.getTabs(),new GSize(200,200),null,null);
}});
});

If you want ot make the infoWindow SMALLER, then the reset method will not work! Why? No one knows… There’s probably a hard-coded minimum height somewhere in google’s code but their documentation doesn’t seem to mention it anywhere.

The infoWindow is made from a handful of divs that are absolutely positioned in the appropriate places. These divs are for the 4 corners and the top, bottom and middle, sorta like a tic-tac-toe board but with one div for the middle row. By manipulating all these div’s style.top appropriately and the height of the middle div, we can actually shrink the infoWindow despite Google API’s best effort to get in our way!

Code to resize infoWindow with a small height:

var infoWindow = map.getInfoWindow();
var point = new GLatLng(0,0);
var marker = new GMarker(point);
GEvent.bind(marker,”click”,{marker:marker,address:address},function() {
map.openInfoWindowHtml(this.marker.getPoint(),this.address,{onOpenFn:function(){
/* Google Maps API does not support any way to resize the infoWindow, this is my hack.
* There is no CSS class to manipulate these divs and the infoWindow.reset method
* CAN be used to increase the size but not to make it smaller.(min height is about 60px).
*/
var infoWindowBlocks = YAHOO.util.Selector.query(’#area-map-tool div div div div’);
for(var c = 0; c < infoWindowBlocks.length; c++){
if(infoWindowBlocks[c].style.height === "40px" && infoWindowBlocks[c].style.top === "25px"){
infoWindowBlocks[c].style.height = "10px";
}
if(infoWindowBlocks[c].style.top === "65px"){
infoWindowBlocks[c].style.top = "35px"
}
}
}});
});

Be sure to change the css selector to the appropriate id of the div that contains your map! mine was area-map-tool!

I have not tested this EXACT code but will hopefully get a demo working here soon. Please let me know if you find any problems!
Cheers!

Tags: , , , , , ,

128 Responses to “How to change size of infoWindow in Google Map with API”

Dennis Says:

Great that you found a solution for reducing the InfoWindow size. Just what I need! Unfortunately your code isn’t working for me. Safari JS debug gives “Error: NOT_FOUND_ERR: DOM Exception 8″ and Firebug says “uncaught exception: Node cannot be inserted at the specified point in the hierarchy (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR). Any idea what could be wrong?

jelqing secrets Says:

Very nice!…

Wow you are very very talented!! keep up the awesome work. You are very talented & I only wish I could write as good as you do :)…

Chantelle Says:

hello…

really good article. Ready to hear more next week,my blog http://talonmpgraham.blog.ca/2011/06/12/adressing-wedding-invites-envelopes-11302585/ Many Thanks….

Matilde Says:

hello…

really good article. Ready to hear more next week,my blog http://eveningdressesypqypq.wordpress.com/2011/06/12/adressing-wedding-invitations-envelopes/ Many Thanks….

Dehmer Says:

really good article…

I have spent a bit of time going through your posts, more than I should have but I must say, its worth it! http://blue071.speedywap.net/?p=5 many Thanks….

venzingS Says:

hello…

Hi there just quality post! http://philomena.eklablog.com/ ,i had a good read.thank you for your article,My problem continues to be resolved….

Eugenie Says:

Great…

You did a great job! http://dennisea.spruz.com/...

Alexander Says:

buy@viagra.online” rel=”nofollow”>…

Need cheap generic VIAGRA?…

Cenzing Says:

Great One…

I must say, its worth it! My link!http://nantz071.blogturk.org/ ,thanks haha…

Alexander7 Says:

buy@generic.LEVITRA” rel=”nofollow”>…

Need cheap generic LEVITRA?…

SETH Says:

Order@Cheap.Coral.Calcium” rel=”nofollow”>..

Buygeneric pills…

BRANDON Says:

Order@Discount.Coral.Calcium” rel=”nofollow”>..

Buyno prescription…

TERRENCE Says:

Purchase@Discount.Coral.Calcium” rel=”nofollow”>..

Buyit now…

SALVADOR Says:

Cheap@Coral.Calcium.Online” rel=”nofollow”>..

Buygeneric meds…

LEWIS Says:

Purchase@Cheap.Abilify” rel=”nofollow”>..

Buynow it…

SALVADOR Says:

Order@Acai.Without.Prescription” rel=”nofollow”>…

Buynow…

RENE Says:

Buy@Coral.Calcium.Online” rel=”nofollow”>.…

Buygeneric drugs…

PERRY Says:

Purchase@Cheap.Abana” rel=”nofollow”>…

Buywithout prescription…

MIKE Says:

Buy@Cheap.Coral.Calcium” rel=”nofollow”>.

Buydrugs without prescription…

EDUARDO Says:

Buy@Abana.Online” rel=”nofollow”>.

Buynow it…

DENNIS Says:

Buy@Acai.Online” rel=”nofollow”>.

Buyit now…

LANCE Says:

Buy@Acai.Online” rel=”nofollow”>…

Buyno prescription…

SAMUEL Says:

Buy@Cheap.Acai” rel=”nofollow”>…

Buygeneric drugs…

FELIX Says:

Buy@Discount.Acai” rel=”nofollow”>…

Buyit now…

ALFRED Says:

Order@Discount.Acai” rel=”nofollow”>…

Buynow…

DONALD Says:

Purchase@Discount.Acai” rel=”nofollow”>…

Buyit now…

KELLY Says:

Cheap@Acai.Online” rel=”nofollow”>.

Buygeneric meds…

VICTOR Says:

Order@Acai.Without.Prescription” rel=”nofollow”>.

Buygeneric drugs…

DUSTIN Says:

Cheap@Acai.500mg” rel=”nofollow”>..…

Buygeneric drugs…

RICK Says:

Order@Energy.Boost.Online” rel=”nofollow”>.…

Buygeneric drugs…

MATHEW Says:

Purchase@Cheap.Energy.Boost” rel=”nofollow”>.…

Buyno prescription…

BILLY Says:

Get@Accupril.Online” rel=”nofollow”>.…

Buygeneric drugs…

WILLIAM Says:

Buy@Aciphex.Online” rel=”nofollow”>.…

Buygeneric pills…

CARL Says:

Buy@Generic.Aciphex” rel=”nofollow”>.…

Buygeneric meds…

ADAM Says:

Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>.…

Buyno prescription…

NATHAN Says:

Purchase@Generic.Aciphex.20mg” rel=”nofollow”>.…

Buynow it…

Pterker Says:

Great…

love your blog, http://jill11.blogdetik.com/ ,Thanks again….

RUBEN Says:

Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.…

Buygeneric meds…

JONATHAN Says:

Purchase@Generic.Actonel” rel=”nofollow”>.

Buygeneric meds vbg…

DARYL Says:

Buy@Actoplus.Met.Online” rel=”nofollow”>..

Buygeneric drugs krg…

VICTOR Says:

Order@Actos.Online” rel=”nofollow”>..

Buygeneric pills zdg…

RAY Says:

Purchase@Generic.Actos” rel=”nofollow”>.

Buygeneric drugs zfk…

CLIFTON Says:

Order@Acular.Online” rel=”nofollow”>..

Buygeneric meds qmo…

MARCUS Says:

Buy@Advair.Online” rel=”nofollow”>..

Buynow it vhx…

LAWRENCE Says:

Purchase@Discount.Abilify” rel=”nofollow”>..

Buywithout prescription dyo…

Gander Says:

Great One…

I must say, its worth it! My link, http://allison11.onsugar.com/,thanks haha…

SERGIO Says:

Order@Generic.Abilify” rel=”nofollow”>.

Buyno prescription luw…

MITCHELL Says:

Generic@Abilify.5mg.10mg.15mg.20mg.30mg.Without.Prescription” rel=”nofollow”>..

Buydrugs without prescription faj…

VINCENT Says:

Purchase@Acai.Online” rel=”nofollow”>.

Buyit now ojb…

RONALD Says:

Buy@Acai.Without.Prescription” rel=”nofollow”>.

Buygeneric drugs itj…

BRYAN Says:

Buy@Generic.Acai.500mg” rel=”nofollow”>.

Buygeneric drugs nih…

CHRISTOPHER Says:

Buy@Energy.Boost.Online” rel=”nofollow”>..

Buynow it cey…

BRUCE Says:

accupril@and.muscle.pain” rel=”nofollow”>…

Buynow it zdg…

HOMER Says:

Purchase@Cheap.Accupril” rel=”nofollow”>..

Buyit now irl…

PHILIP Says:

Purchase@Discount.Accupril” rel=”nofollow”>…

Buygeneric meds svb…

MARVIN Says:

Cheap@Accutane.Online” rel=”nofollow”>.

Buynow it lmg…

JASON Says:

Buy@Cheap.Aciphex” rel=”nofollow”>…

Buywithout prescription ccw…

Chantelle Says:

really…

Fat women and girls always worried because of their ugly shaped bodies. http://druyjkiodruyjkio.scoom.com/ , but they can not wear these outwears…

MARION Says:

Cheap@Aciphex.Online” rel=”nofollow”>..

Buyno prescription gdt…

DALE Says:

Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>…

Buyit now knc…

JOEL Says:

Buy@Acomplia.Online” rel=”nofollow”>..

Buyno prescription wkp…

CHRIS Says:

Cheap@Acomplia.Online” rel=”nofollow”>..

Buygeneric drugs nvr…

DWIGHT Says:

Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.

Buygeneric drugs ouw…

RICARDO Says:

Buy@Cheap.Advair” rel=”nofollow”>.

Buygeneric drugs hwi…

FRED Says:

Purchase@Advair.Online” rel=”nofollow”>..

Buyno prescription jui…

ALEXANDER Says:

Order@Aggrenox.Online” rel=”nofollow”>…

Buyit now sge…

STEVE Says:

Get@Albenza.Online” rel=”nofollow”>…

Buynow fjl…

BRENT Says:

abilify@and.weight.gain” rel=”nofollow”>…

Buyno prescription…

ANGELO Says:

aciphex@cancer.buy” rel=”nofollow”>..

Buygeneric drugs…

BRYAN Says:

can@you.get.acai.berries.in.the.grocery.store” rel=”nofollow”>.

Buydrugs without prescription…

JULIUS Says:

..

Buyit now…

OLIVER Says:

phamacokinetic@of.amikacin” rel=”nofollow”>..

Buygeneric drugs…

MARTIN Says:

ampicillin@500.mg” rel=”nofollow”>.

Buydrugs without prescription…

TYLER Says:

buy@real.strong.armour” rel=”nofollow”>.

Buydrugs without prescription…

Frederic Says:

very helpful…

I preferred to thank you for this good article. http://lychtb.quebecblogue.com/2011/09/01/beach-flowy-wedding-gowns-for-older-brides/ I by all odds liked every little bit of it…

LUIS Says:

cancer tattoos

Buy_without prescription…

Benzing Says:

Great…

What are the specific differences between a sport in the regular Olympics and a sport in the Special Olympics?, http://annie11.grou.ps/groups/191818...

DON Says:

medication for ibs

Buy_generic drugs…

JESSIE Says:

boniva price

Buy_drugs without prescription…

JAY Says:

effexor xr 75

Buy_generic pills…

DENNIS Says:

low fat diets history

Buy_drugs without prescription…

JOEY Says:

atkins diet first week foods

Buy_without prescription…

LUKE Says:

dog hives and what causes them

Buy_drugs without prescription…

KYLE Says:

depression amino acids

Buy_drugs without prescription…

STANLEY Says:

green@mountain.coffee.cafe.club” rel=”nofollow”>…

Buygeneric meds…

RAMON Says:

children@prozac.buy” rel=”nofollow”>…

Buywithout prescription…

Leave a Reply