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 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 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: API, Google Map, height, infoWindow, reset, resize, size
128 Responses to “How to change size of infoWindow in Google Map with API”
May 26th, 2009 at 3:09 am
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?
April 16th, 2011 at 3:24 am
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 :)…
June 12th, 2011 at 10:57 pm
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….
June 13th, 2011 at 4:19 pm
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….
June 16th, 2011 at 2:50 am
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….
June 20th, 2011 at 3:30 am
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….
June 21st, 2011 at 1:56 pm
Great…
You did a great job! http://dennisea.spruz.com/...
June 22nd, 2011 at 5:03 am
Great…
You did a great job! http://davina.blogviaje.com/1308482690/...
July 6th, 2011 at 8:13 pm
buy@viagra.online” rel=”nofollow”>……
Need cheap generic VIAGRA?…
July 18th, 2011 at 3:36 pm
Great One…
I must say, its worth it! My link!http://nantz071.blogturk.org/ ,thanks haha…
July 22nd, 2011 at 1:35 pm
buy@generic.LEVITRA” rel=”nofollow”>……
Need cheap generic LEVITRA?…
July 29th, 2011 at 12:27 am
Order@Cheap.Coral.Calcium” rel=”nofollow”>..…
Buygeneric pills…
July 29th, 2011 at 12:51 am
Order@Discount.Coral.Calcium” rel=”nofollow”>..…
Buyno prescription…
July 29th, 2011 at 2:02 am
Purchase@Discount.Coral.Calcium” rel=”nofollow”>..…
Buyit now…
July 29th, 2011 at 2:26 am
Cheap@Coral.Calcium.Online” rel=”nofollow”>..…
Buygeneric meds…
July 29th, 2011 at 1:01 pm
Purchase@Cheap.Abilify” rel=”nofollow”>..…
Buynow it…
July 31st, 2011 at 1:15 am
Order@Acai.Without.Prescription” rel=”nofollow”>……
Buynow…
July 31st, 2011 at 11:40 am
Buy@Coral.Calcium.Online” rel=”nofollow”>.…
Buygeneric drugs…
July 31st, 2011 at 7:21 pm
Purchase@Cheap.Abana” rel=”nofollow”>……
Buywithout prescription…
August 1st, 2011 at 11:36 pm
Buy@Cheap.Coral.Calcium” rel=”nofollow”>.…
Buydrugs without prescription…
August 2nd, 2011 at 5:56 am
Buy@Abana.Online” rel=”nofollow”>.…
Buynow it…
August 3rd, 2011 at 12:11 pm
Buy@Acai.Online” rel=”nofollow”>.…
Buyit now…
August 3rd, 2011 at 12:11 pm
Buy@Acai.Online” rel=”nofollow”>……
Buyno prescription…
August 3rd, 2011 at 1:21 pm
Buy@Cheap.Acai” rel=”nofollow”>……
Buygeneric drugs…
August 3rd, 2011 at 3:03 pm
Buy@Discount.Acai” rel=”nofollow”>……
Buyit now…
August 3rd, 2011 at 7:35 pm
Order@Discount.Acai” rel=”nofollow”>……
Buynow…
August 4th, 2011 at 12:43 am
Purchase@Discount.Acai” rel=”nofollow”>……
Buyit now…
August 4th, 2011 at 1:49 am
Cheap@Acai.Online” rel=”nofollow”>.…
Buygeneric meds…
August 4th, 2011 at 3:59 pm
Order@Acai.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs…
August 4th, 2011 at 8:22 pm
Cheap@Acai.500mg” rel=”nofollow”>..…
Buygeneric drugs…
August 5th, 2011 at 1:14 am
Order@Energy.Boost.Online” rel=”nofollow”>.…
Buygeneric drugs…
August 5th, 2011 at 5:49 am
Purchase@Cheap.Energy.Boost” rel=”nofollow”>.…
Buyno prescription…
August 5th, 2011 at 10:06 pm
Get@Accupril.Online” rel=”nofollow”>.…
Buygeneric drugs…
August 7th, 2011 at 2:44 am
Buy@Aciphex.Online” rel=”nofollow”>.…
Buygeneric pills…
August 7th, 2011 at 6:43 pm
Buy@Generic.Aciphex” rel=”nofollow”>.…
Buygeneric meds…
August 7th, 2011 at 8:45 pm
Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>.…
Buyno prescription…
August 8th, 2011 at 2:10 pm
Purchase@Generic.Aciphex.20mg” rel=”nofollow”>.…
Buynow it…
August 9th, 2011 at 4:19 am
Great…
love your blog, http://jill11.blogdetik.com/ ,Thanks again….
August 10th, 2011 at 12:47 am
Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.…
Buygeneric meds…
August 10th, 2011 at 1:44 pm
Purchase@Generic.Actonel” rel=”nofollow”>.…
Buygeneric meds vbg…
August 10th, 2011 at 7:51 pm
Buy@Actoplus.Met.Online” rel=”nofollow”>..…
Buygeneric drugs krg…
August 11th, 2011 at 3:41 am
Order@Actos.Online” rel=”nofollow”>..…
Buygeneric pills zdg…
August 11th, 2011 at 1:57 pm
Purchase@Generic.Actos” rel=”nofollow”>.…
Buygeneric drugs zfk…
August 12th, 2011 at 3:40 am
Order@Acular.Online” rel=”nofollow”>..…
Buygeneric meds qmo…
August 12th, 2011 at 3:31 pm
Buy@Advair.Online” rel=”nofollow”>..…
Buynow it vhx…
August 13th, 2011 at 8:10 am
Purchase@Discount.Abilify” rel=”nofollow”>..…
Buywithout prescription dyo…
August 13th, 2011 at 8:16 am
Great One…
I must say, its worth it! My link, http://allison11.onsugar.com/,thanks haha…
August 13th, 2011 at 12:51 pm
Order@Generic.Abilify” rel=”nofollow”>.…
Buyno prescription luw…
August 13th, 2011 at 8:19 pm
Generic@Abilify.5mg.10mg.15mg.20mg.30mg.Without.Prescription” rel=”nofollow”>..…
Buydrugs without prescription faj…
August 14th, 2011 at 5:01 am
Purchase@Acai.Online” rel=”nofollow”>.…
Buyit now ojb…
August 14th, 2011 at 12:06 pm
Buy@Acai.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs itj…
August 14th, 2011 at 10:48 pm
Buy@Generic.Acai.500mg” rel=”nofollow”>.…
Buygeneric drugs nih…
August 15th, 2011 at 5:35 am
Buy@Energy.Boost.Online” rel=”nofollow”>..…
Buynow it cey…
August 15th, 2011 at 5:53 pm
accupril@and.muscle.pain” rel=”nofollow”>……
Buynow it zdg…
August 16th, 2011 at 6:37 am
Purchase@Cheap.Accupril” rel=”nofollow”>..…
Buyit now irl…
August 16th, 2011 at 7:43 am
Purchase@Discount.Accupril” rel=”nofollow”>……
Buygeneric meds svb…
August 17th, 2011 at 2:24 am
Cheap@Accutane.Online” rel=”nofollow”>.…
Buynow it lmg…
August 17th, 2011 at 11:39 pm
Buy@Cheap.Aciphex” rel=”nofollow”>……
Buywithout prescription ccw…
August 18th, 2011 at 8:48 am
really…
Fat women and girls always worried because of their ugly shaped bodies. http://druyjkiodruyjkio.scoom.com/ , but they can not wear these outwears…
August 18th, 2011 at 9:15 am
Cheap@Aciphex.Online” rel=”nofollow”>..…
Buyno prescription gdt…
August 18th, 2011 at 3:10 pm
Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>……
Buyit now knc…
August 19th, 2011 at 7:46 am
Buy@Acomplia.Online” rel=”nofollow”>..…
Buyno prescription wkp…
August 21st, 2011 at 1:51 am
Cheap@Acomplia.Online” rel=”nofollow”>..…
Buygeneric drugs nvr…
August 22nd, 2011 at 1:17 am
Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.…
Buygeneric drugs ouw…
August 22nd, 2011 at 6:36 am
Buy@Cheap.Advair” rel=”nofollow”>.…
Buygeneric drugs hwi…
August 23rd, 2011 at 2:48 am
Purchase@Advair.Online” rel=”nofollow”>..…
Buyno prescription jui…
August 24th, 2011 at 4:08 am
Buy@Generic.Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>..< …
Buydrugs without prescription hak…
August 24th, 2011 at 5:28 am
Buy@Generic.Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>..< …
Buyno prescription lka…
August 24th, 2011 at 6:10 pm
Order@Aggrenox.Online” rel=”nofollow”>……
Buyit now sge…
August 25th, 2011 at 6:10 pm
Get@Albenza.Online” rel=”nofollow”>……
Buynow fjl…
August 26th, 2011 at 5:55 am
abilify@and.weight.gain” rel=”nofollow”>……
Buyno prescription…
August 26th, 2011 at 7:14 pm
aciphex@cancer.buy” rel=”nofollow”>..…
Buygeneric drugs…
August 28th, 2011 at 3:33 am
can@you.get.acai.berries.in.the.grocery.store” rel=”nofollow”>.…
Buydrugs without prescription…
August 28th, 2011 at 11:28 pm
..…
Buyit now…
August 29th, 2011 at 12:45 am
phamacokinetic@of.amikacin” rel=”nofollow”>..…
Buygeneric drugs…
August 29th, 2011 at 2:56 am
ampicillin@500.mg” rel=”nofollow”>.…
Buydrugs without prescription…
August 29th, 2011 at 9:35 am
buy@real.strong.armour” rel=”nofollow”>.…
Buydrugs without prescription…
September 1st, 2011 at 5:07 pm
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…
October 17th, 2011 at 8:39 pm
mike divorce cancer tiffany…
Buy_generic pills…
October 18th, 2011 at 9:36 am
methotrexate and tricyclerides side effects…
Buy_generic pills…
October 18th, 2011 at 2:35 pm
cancer tattoos…
Buy_without prescription…
October 19th, 2011 at 2:16 am
boulder valley asthma and allergy clinic…
Buy_no prescription…
October 21st, 2011 at 2:27 pm
obesity children summer…
Buy_it now…
October 21st, 2011 at 2:37 pm
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...
October 22nd, 2011 at 7:07 am
prostate cancer injection treatment…
Buy_now it…
October 23rd, 2011 at 5:23 am
medication for ibs…
Buy_generic drugs…
October 25th, 2011 at 12:08 am
red wine and lipitor…
Buy_no prescription…
October 26th, 2011 at 1:08 am
follistim increase estradiol levels…
Buy_generic drugs…
October 26th, 2011 at 12:48 pm
effects of bulimia only sometimes…
Buy_generic meds…
October 27th, 2011 at 12:28 am
boniva price…
Buy_drugs without prescription…
October 27th, 2011 at 7:08 am
effexor xr 75…
Buy_generic pills…
October 27th, 2011 at 1:48 pm
genital erection…
Buy_now it…
October 27th, 2011 at 3:27 pm
low fat diets history…
Buy_drugs without prescription…
October 27th, 2011 at 11:47 pm
australia clinical research resume…
Buy_generic drugs…
October 28th, 2011 at 6:08 pm
tests for assessing anxiety…
Buy_now it…
October 28th, 2011 at 8:44 pm
thyroid scan image…
Buy_generic pills…
October 29th, 2011 at 6:41 am
hives rash from coming off prednisone…
Buy_generic drugs…
October 29th, 2011 at 1:21 pm
side effects of luvox…
Buy_now…
October 31st, 2011 at 5:45 pm
tylenol without codeine related constipation…
Buy_it now…
November 1st, 2011 at 2:05 am
what is metoprolol succinate used for…
Buy_it now…
November 1st, 2011 at 10:25 am
zocor and ms…
Buy_it now…
November 1st, 2011 at 5:05 pm
adderall then tylenol pm…
Buy_generic drugs…
November 1st, 2011 at 10:06 pm
abdominal pain lutenizing hormone…
Buy_generic drugs…
November 2nd, 2011 at 3:06 am
advantage of skin cancer…
Buy_generic drugs…
November 2nd, 2011 at 4:45 am
negative thyroid test…
Buy_no prescription…
November 2nd, 2011 at 8:06 am
ic tramadol hcl 50 mg…
Buy_generic meds…
November 2nd, 2011 at 4:25 pm
household chemicals that kill fleas…
Buy_now it…
November 3rd, 2011 at 1:13 pm
atkins diet first week foods…
Buy_without prescription…
November 3rd, 2011 at 11:13 pm
hot dog hospital diet substitutions…
Buy_generic drugs…
November 4th, 2011 at 9:50 pm
dog hives and what causes them…
Buy_drugs without prescription…
November 5th, 2011 at 4:10 pm
depression amino acids…
Buy_drugs without prescription…
November 5th, 2011 at 7:30 pm
best drug store foundation…
Buy_generic meds…
November 6th, 2011 at 8:50 am
when develop toxemia pregnancy…
Buy_it now…
November 7th, 2011 at 3:10 am
period changes leading up to menopause…
Buy_it now…
November 7th, 2011 at 4:50 am
allergic reaction to topical miconazole…
Buy_generic meds…
November 7th, 2011 at 4:30 pm
drug additiction symptoms…
Buy_generic meds…
November 9th, 2011 at 1:04 am
twin pregnancy obstetrician specialist dallas…
Buy_drugs without prescription…
November 9th, 2011 at 11:04 am
psychotic depression and philadelphia…
Buy_generic meds…
November 9th, 2011 at 12:44 pm
shampoo for people with dog allergies…
Buy_now…
November 10th, 2011 at 5:04 pm
new birth control pill…
Buy_now it…
November 11th, 2011 at 11:24 am
menopause thyroid cancer…
Buy_without prescription…
November 12th, 2011 at 7:24 am
zocor orange juice effects…
Buy_no prescription…
November 12th, 2011 at 9:04 am
boniva and bone thinning and breaks…
Buy_now it…
November 13th, 2011 at 6:24 pm
tsa drug dogs for adoptino…
Buy_generic drugs…
November 15th, 2011 at 2:02 pm
free fast diet tips…
Buy_generic meds…
December 9th, 2011 at 2:23 am
green@mountain.coffee.cafe.club” rel=”nofollow”>……
Buygeneric meds…
December 10th, 2011 at 1:16 am
children@prozac.buy” rel=”nofollow”>……
Buywithout prescription…
December 23rd, 2011 at 2:43 pm
advair diskus…
advair diskus…
Leave a Reply