Working with Info Windows in Google Maps
Having Info Windows in a Google Maps is a powerful way of displaying information about a specific point or object. Did you know that there are several kinds of them?
In this article I will show you how to add different kinds of Info Windows that appear when you click on a marker.
Content
- Basic Info Window
- Info window with tabs
- Info Window containing a Mini map
- Maximizing the Info Window
- Options
- Conclusion and further resources
Basic Info Window
The key method for opening an info window when clicking a marker is GMarker.openInfoWindowHTML(). It takes two arguments, first the text that will appear in the Info Window and secondly an optional object literal containing options you might want to use to configure the Info Window. To learn more about the available options, see Options further down the page.
In the examples for this article you have to click a marker to open the window. This is done by using the GEvent.addListener() method. I will not describe exactly how it works in this article but if you’re unfamiliar with it you can read more about it in the official documentation.
// Init a new map
var map = new GMap2(document.getElementById('map'));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(56.87, 14.80), 11);
// Creating a new marker
var marker = new GMarker(new GLatLng(56.87, 14.80))
// Adding a click-event to the marker
GEvent.addListener(marker, 'click', function() {
// When clicked, open an Info Window
marker.openInfoWindowHtml('Some text');
});
// Add marker to map
map.addOverlay(marker);
This code will result in an ordinary map showing a marker which, when you click on it, pops up an Info Window.

Info Window with Tabs
If you have a lot of information about each marker, more than you can fit inside a normal Info Window, you could use an Info Window with tabs. You simply define each tab as a GInfoWindowTab and add them to an array that you later on add to the marker using the openInfoWindowTabsHtml() method.
// Create an array that will hold the tabs
var tabs = [];
// Create tabs and add them to the array
tabs.push(new GInfoWindowTab('Tab 1', 'Content of tab 1'));
tabs.push(new GInfoWindowTab('Tab 2', 'Content of tab 2'));
// Add tabs to the InfowWindow
marker.openInfoWindowTabsHtml(tabs);
The result is a tabbed Info Window.

Info Window containing a Mini map
The API features an easy method to open up a mini map over the area where the marker is located, showMapBlowup(opts?:GInfoWindowOptions). This method takes an object literal that have two possible parameters, InfoWindowOptions.zoomLevel and InfoWindowOptions.mapType. These lets you determine at what zoom-level the mini map should start and what map type it should show.
GEvent.addListener(marker, 'click', function() {
// When clicked, open an Info Window with a min map in it
marker.showMapBlowup();
});
You never thought it would be this easy to do this, did you?

Maximizing the Info Window
If you have a lot of content to show in you Info Window it could be useful to let the user maximize it. This is easily done using the options maxContent and maxTitle. If you define these you will automatically get a maximize button in your window.
So to make this work just do like this.
marker.openInfoWindowHtml('Click the (+) to maximize me!', {
maxTitle: 'Maximized Title',
maxContent: 'Maximized content text.'
});
When you first click the marker an ordinary info window will pop up. When you click the plus sign (+) in it, it will maximize.

Options
As I’ve mentioned earlier each of the methods that opens an Info Window takes an optional object literal with options. The properties you can use in it are defined in the GInfoWindowOptions class.
All properties doesn’t comply with all kinds of Info Window.
- selectedTab [number]
Determines which tab should be selected when opening an Info Window. Starts with number 0. - maxWidth [number]
Sets the maximum width of the info window. Note: From my observations it seems that the minimum value for this is 249 pixels. - noCloseOnClick [bool]
Sets if the info window should be closed when clicking inside the map. Default value is true. - onOpenFn [Function]
A function that is called after the info window is opened and the content is displayed. - onCloseFn [Function]
A function that is called when the info window is closed. - zoomLevel [number]
Determines what zoom level an opened Mini Map should have. Only applicable with showMapBlowUp(). - mapType [GMapType]
Determines what map type an opened Mini Map should have. Only applicable with showMapBlowUp(). - maxContent [string]
Determines what content should be showed when an info window is maximized. It can be either an HTML string or an HTML DOM element. - maxTitle [string]
Sets the title for the window when it’s maximized. It can be either an HTML string or an HTML DOM element. - pixelOffset [GSize]
Specifies a number of pixels to move the info window away from the current GLatLng.
How to use them
The options are passed to the method in an Object Literal. Here’s an example of using the maxWidth property when opening a basic Info Window.
marker.openInfoWindowHtml('Some text', {maxWidth: '250'});
Conclusion and further resources
Info windows are a powerful way of displaying information about certain objects in a map. In this article I have showed you some of the basic ways to use the built in ones in Google Maps. I think you can go a long way with these techniques but if you have special needs there are third party extensions out there that you can use.
It’s beyond the scope of this article to describe how they work, but the first library to check out should be ExtInfoWindow, one of the open source utility libraries for Google Maps. You’ll find documentation and examples at Google Maps API Utility Library. Joe Monahan has also written some about it on the Google Maps API Blog in the article ExtInfoWindow 1.0: Ajax powered, CSS customization.
Mike William at Google Maps API Tutorial has described two other libraries in the tutorials Using the EWindow extension and Using the EBubble extension that also might be useful.
Happy coding!
My Google Maps book
If you found this article useful you might be interested in my book Beginning Google Maps API 3. It covers everything you need to know to create awesome maps on your web sites. Buy it on Amazon.com
About the author
Gabriel Svennerberg is an independent Interaction/UI Designer and Web Developer living in Sweden. When he's not busy building web application designed for humans, he writes about all things web on his site In usability we trust. Gabriel is the author of the book Beginning Google Maps API 3 published by Apress.-
http://www.heavyworks.net Jan Seidl
-
http://imagine-it.org Pamela Fox
-
http://www.svennerberg.com Gabriel Svennerberg
-
Dishaniti
-
kv
-
http://www.svennerberg.com Gabriel Svennerberg
-
Karthik
-
estebam
-
http://www.svennerberg.com Gabriel Svennerberg
-
http://learninggooglemaps.wordpress.com/2009/03/02/day-4-a-bit-more-of-kml-custom-icons-and-info-boxes/ Day 4 – a bit more of KML, custom icons and info boxes « Learning Google Maps API
-
Brian Goldsberry
-
http://www.svennerberg.com Gabriel Svennerberg
-
zuputti
-
http://www.svennerberg.com Gabriel Svennerberg
-
Dee
-
http://faviconstore.com rob
-
Nestor Fuhr
-
Ary
-
http://www.svennerberg.com Gabriel Svennerberg
-
http://golez.wordpress.com/ Bosti
-
Barton
-
Adrian Power
-
http://www.svennerberg.com Gabriel Svennerberg
-
Adrian Power
-
Ay
-
http://www.svennerberg.com Gabriel Svennerberg
-
Geoff
-
http://www.svennerberg.com Gabriel Svennerberg
-
Herman
-
http://137.229.80.178/janel/example_porcupine_clearbox.html jamie
-
http://blackberrythemewall.com deerawan
-
Sam
-
http://sudhakar.com M.sudhakar
-
dj
-
nick
-
Hawk
-
http://nelsonwhitewaterrafting.com/river_map.html greg_dd
-
Ali
-
kremilek10
-
http://www.digitalbugs.pl Darmowy katalog stron
-
Mitch
-
http://www.tuvizio.com argenis
-
http://www.svennerberg.com Gabriel Svennerberg
-
Chris
-
niraj
-
niraj
-
http://www.survquest.com/abdul/2.html abdulwasiu
-
Benedikt