Skip to content

InfoWindow

<InfoWindow /> component is used for display content (usually text or images) in a popup window above the map, at a given location. for more detail, see official google map documentation.

Basic Example

const uluru = { lat: -25.363, lng: 131.044 };
function Content() {
return (
<div id='content'>
<div id='siteNotice'></div>
<h1 id='firstHeading' className='firstHeading'>Uluru</h1>
<div id='bodyContent'>
<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large sandstone rock formation in the southern part of the Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) south west of the nearest large town, Alice Springs; 450&#160;km (280&#160;mi) by road. Kata Tjuta and Uluru are the two major features of the Uluru - Kata Tjuta National Park. Uluru is sacred to the Pitjantjatjara and Yankunytjatjara, the Aboriginal people of the area. It has many springs, waterholes, rock caves and ancient paintings. Uluru is listed as a World Heritage Site.</p>
<p>Attribution: Uluru, <a href='https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194'>https://en.wikipedia.org/w/index.php?title=Uluru</a> (last visited June 22, 2009).</p>
</div>
</div>
);
}
function MyMap() {
const [isOpen, setOpen] = useState(false);
return (
<GoogleMap
className='h-[400px]'
zoom={4}
center={uluru}
>
<InfoWindow ariaLabel='Uluru' content={<Content />} onCloseClick={() => setOpen(false)} open={isOpen}>
<Marker {...uluru} title='Uluru (Ayers Rock)' onClick={() => setOpen(true)} />
</InfoWindow>
</GoogleMap>
);
}

Props

PropsTypeDescription
openbooleanInfoWindow open flag. if flag is set to true, InfoWindow will be displayed on the map.
shouldFocusbooleanWhether or not focus should be moved inside the InfoWindow when it is opened.
ariaLabelstringAriaLabel to assign to the InfoWindow.
contentReactElement<unknown> | string | Element | TextContent to display in the InfoWindow.
disableAutoPanbooleanDisable panning the map to make the InfoWindow fully visible when it opens.
maxWidthnumberMaximum width of the InfoWindow
minWidthnumberMinimum width of the InfoWindow
pixelOffsetgoogle.maps.SizeThe offset, in pixels, of the tip of the info window from the point on the map at whose geographical coordinates the info window is anchored.
positiongoogle.maps.LatLng | google.maps.LatLngLiteralThe LatLng at which to display this InfoWindow. If the InfoWindow is opened with Marker children(anchor), the anchor’s position will be used instead.
zIndexnumberzIndex for InfoWindow.
onCloseClick(infoWindow: google.maps.InfoWindow) => voidcallback for closeclick event. Please refer to the official documentation.
onContentChanged(infoWindow: google.maps.InfoWindow) => voidcallback for content_changed event. Please refer to the official documentation.
onDomReady(infoWindow: google.maps.InfoWindow) => voidcallback for domready event. Please refer to the official documentation.
onPositionChanged(infoWindow: google.maps.InfoWindow) => voidcallback for position_changed event. Please refer to the official documentation.
onVisible(infoWindow: google.maps.InfoWindow) => voidcallback for visible event. Please refer to the official documentation.
onZIndexChanged(infoWindow: google.maps.InfoWindow) => voidcallback for zindex_changed event. Please refer to the official documentation.

Anchor

If you pass Marker or AdvancedMarker to children, it will be used as an anchor.

The anchor to which this InfoWindow will be positioned. If the anchor is non-null, the InfoWindow will be positioned at the top-center of the anchor. The InfoWindow will be rendered on the same map or panorama as the anchor (when available).

otherwise you can