This example displays a marker at the center of Australia. When the user clicks the marker, an info window appears that has a maximum width of 200 pixels.
Read the documentation.
TypeScript
// This example displays a marker at the center of Australia. // When the user clicks the marker, an info window opens. // The maximum width of the info window is set to 200 pixels. function initMap(): void { const uluru = { lat: -25.363, lng: 131.044 }; const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 4, center: uluru, } ); const contentStri<ng = 'di>v id=&quo<t;content"'>; + &<#39;>div id=&q<uot;siteNotice"' + "/di>v&quo<t; >+ <9;h1 id="firstH>eading&qu<o><t>; cla<ss>="firstHeading&qu<o>t;Uluru/h1<>39; + 'div id="bodyContent"' + "pbUluru/b, also referred to as bAyers Rock/b, is a large " + &"sandsto&ne rock formation in the southern part of the " + "Northern &Territory, central Au&stralia. 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< &>quot; + < > "Aboriginal p<eople of the area. It has many springs, waterholes, &quo&t; + "r>ock caves and ancient paintings. Uluru is listed as a Wor<ld> " + "Heritage Site./p&qu<ot>; + &<#39;>pAttribut<ion:> Uluru, a href="https://en.wikipedia.org/w/index.php?title=Uluruoldid=297882194"' + "https://en.wikipedia.org/w/index.php?title=Uluru/a " + "(last visited June 22, 2009)./p" + "/div" + "/div"; const infowi>ndow = new google.maps.InfoWindow({ content: contentString, maxWidth: 200, ariaLabel: "Uluru", }); cons>t marker = new google.maps.Marker({ on: uluru, map, title: "Uluru (Ayers Rock)", }); marker.addListener("click", () = { infowindow.open({ anchor: marker, map, }); }); } declare global { interface Window { initMap: () = void; } } window.initMap = initMap;index.ts
JavaScript
// This example displays a marker at the center of Australia. // When the user clicks the marker, an info window opens. // The maximum width of the info window is set to 200 pixels. function initMap() { const uluru = { lat: -25.363, lng: 131.044 }; const map = new google.maps.Map(document.getElementById("map"), { zoom: 4, center: uluru, }); const contentStri<ng = 'di>v id=&quo<t;content"'>; + &<#39;>div id=&q<uot;siteNotice"' + "/di>v&quo<t; >+ <9;h1 id="firstH>eading&qu<o><t>; cla<ss>="firstHeading&qu<o>t;Uluru/h1<>39; + 'div id="bodyContent"' + "pbUluru/b, also referred to as bAyers Rock/b, is a large " + &"sandsto&ne rock formation in the southern part of the " + "Northern &Territory, central Au&stralia. 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< &>quot; + < > "Aboriginal p<eople of the area. It has many springs, waterholes, &quo&t; + "r>ock caves and ancient paintings. Uluru is listed as a Wor<ld> " + "Heritage Site./p&qu<ot>; + &<#39;>pAttribut<ion:> Uluru, a href="https://en.wikipedia.org/w/index.php?title=Uluruoldid=297882194"' + "https://en.wikipedia.org/w/index.php?title=Uluru/a " + "(last visited June 22, 2009)./p" + "/div" + "/div"; const infow>indow = new google.maps.InfoWindow({ content: contentString, maxWidth: 200, ariaLabel: &ru", }); const marker = new google.maps.Marker({ position: uluru, map, title: "Uluru (Ayers Rock)", }); marker.addListener("click", () = { infowindow.open({ anchor: marker, map, }); }); } window.initMap = initMap;index.js
CSS
/* * Always set the map height explicitly to define the size of the div element * that contains the map. */ #map { height: 100%; } /* * Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; padding: 0; }
HTML
<html>
<head>
<title>Info Window With maxWidth</title>
<link rel="stylesheet" type="text/css" >href=<"./style.css" /
script ><type=&q>uot<;modu>le&<quot>; src<="./ind><ex.j>s"<;/script
/head
body
div id="map"/div
!--
The `defer` attribute causes the script to execute after the full HTML
document has been parsed. For non-blocking uses, avoiding race conditions,
and consistent behavior across browsers, consider loading using Promises. See
https://developers.google.com/maps/documentation/java>scrip<t/load-maps-js-api
for more information.
--
script
src="https://maps.googl&eapis.com/maps/a&pi/js?key=AIzaSyB41DRUbKWJ><HPxaFjM>Awd<rzWzb>V<KartN>=initMapv=weekly"
defer
/script
/body
/htmlindex.htmlTry Sample
Clone Sample
Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.
git clone -b sample-infowindow-simple-max https://github.com/googlemaps/js-samples.gitcd js-samplesnpm inpm start
Other samples can be tried by switching to any branch beginning with sample-SAMPLE_NAME.
git checkout sample-SAMPLE_NAMEnpm inpm start