An info window displays text or images in a popup window above the map. Info windows are always anchored to a marker. Their default behavior is to display when the marker is tapped.
An info window allows you to display information to the user when they tap on a marker. Only one info window is displayed at a time. If a user clicks on another marker, the current info window will be hidden and the new info window will be displayed.
An info window is drawn oriented against the device's screen, centered above its associated marker. The default info window contains the title in bold, with the (optional) snippet text below the title.
Add an info window
The simplest way to add an info window is to set the
methods of the corresponding marker. Setting these properties will cause an
info window to appear whenever that marker is clicked.
static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298); Marker melbourne = mMap.addMarker(new MarkerOptions() .position(MELBOURNE) .title("Melbourne") .snippet("Population: 4,137,400"));
Show/Hide an info window
Info windows are designed to respond to user touch events. If you prefer, you
can show an info window programmatically by calling
showInfoWindow() on the
target marker. An info window can be hidden by calling
static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298); Marker melbourne = mMap.addMarker(new MarkerOptions() .position(MELBOURNE) .title("Melbourne")); melbourne.showInfoWindow();
Custom info windows
You are also able to customize the contents and design of info windows.
To do this, you must create a concrete implementation of the
InfoWindowAdapter interface and then call
GoogleMap.setInfoWindowAdapter() with your
implementation. The interface contains two methods for you to implement:
getInfoContents(Marker). The API will
getInfoWindow(Marker) and if
null is returned, it will then
getInfoContents(Marker). If this also returns
null, then the
default info window will be used.
The first of these (
getInfoWindow()) allows you to provide a view that
will be used for the entire info window. The second of these
getInfoContents()) allows you to just customize the contents of the window
but still keep the default info window frame and background.
The images below show a default info window, an info window with customized contents, and an info window with customized frame and background.
Info window events
You can use an
listen to click events on an info window. To set this listener on the map,
a user clicks on an info window,
onInfoWindowClick(Marker) will be called
and the info window will be highlighted in the default highlight color (Holo
Blue for devices running Ice Cream Sandwich and newer, orange for earlier
versions of Android).
As mentioned in the previous section on info windows, an info window is not a
View, rather the view is rendered as an image onto the map. As a
result, any listeners you set on the view are disregarded and you cannot
distinguish between click events on various parts of the view. You are advised
not to place interactive components — such as buttons, checkboxes, or text
inputs — within your custom info window.