Stay organized with collections
Save and categorize content based on your preferences.
This example creates a map that displays markers to denote various locations
around Astor Place, New York City. It includes a toggle to switch to Street
View, where the same markers are visible.
letpanorama:google.maps.StreetViewPanorama;functioninitMap():void{constastorPlace={lat:40.729884,lng:-73.990988};// Set up the mapconstmap=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{center:astorPlace,zoom:18,streetViewControl:false,});document.getElementById("toggle")!.addEventListener("click",toggleStreetView);constcafeIcon=document.createElement("img");cafeIcon.src="https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg";constdollarIcon=document.createElement("img");dollarIcon.src="https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg";constbusIcon=document.createElement("img");busIcon.src="https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg";// Set up the markers on the mapconstcafeMarker=newgoogle.maps.Marker({position:{lat:40.730031,lng:-73.991428},map,title:"Cafe",icon:cafeIcon.src,});constbankMarker=newgoogle.maps.Marker({position:{lat:40.729681,lng:-73.991138},map,title:"Bank",icon:dollarIcon.src,});constbusMarker=newgoogle.maps.Marker({position:{lat:40.729559,lng:-73.990741},map,title:"Bus Stop",icon:busIcon.src,});// We get the map's default panorama and set up some defaults.// Note that we don't yet set it visible.panorama=map.getStreetView()!;// TODO fix typepanorama.setPosition(astorPlace);panorama.setPov(/** @type {google.maps.StreetViewPov} */{heading:265,pitch:0,});}functiontoggleStreetView():void{consttoggle=panorama.getVisible();if(toggle==false){panorama.setVisible(true);}else{panorama.setVisible(false);}}declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
letpanorama;functioninitMap(){constastorPlace={lat:40.729884,lng:-73.990988};// Set up the mapconstmap=newgoogle.maps.Map(document.getElementById("map"),{center:astorPlace,zoom:18,streetViewControl:false,});document.getElementById("toggle").addEventListener("click",toggleStreetView);constcafeIcon=document.createElement("img");cafeIcon.src="https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg";constdollarIcon=document.createElement("img");dollarIcon.src="https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg";constbusIcon=document.createElement("img");busIcon.src="https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg";// Set up the markers on the mapconstcafeMarker=newgoogle.maps.Marker({position:{lat:40.730031,lng:-73.991428},map,title:"Cafe",icon:cafeIcon.src,});constbankMarker=newgoogle.maps.Marker({position:{lat:40.729681,lng:-73.991138},map,title:"Bank",icon:dollarIcon.src,});constbusMarker=newgoogle.maps.Marker({position:{lat:40.729559,lng:-73.990741},map,title:"Bus Stop",icon:busIcon.src,});// We get the map's default panorama and set up some defaults.// Note that we don't yet set it visible.panorama=map.getStreetView();// TODO fix typepanorama.setPosition(astorPlace);panorama.setPov(/** @type {google.maps.StreetViewPov} */{heading:265,pitch:0,},);}functiontoggleStreetView(){consttoggle=panorama.getVisible();if(toggle==false){panorama.setVisible(true);}else{panorama.setVisible(false);}}window.initMap=initMap;
/* * 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;}#floating-panel{position:absolute;top:10px;left:25%;z-index:5;background-color:#fff;padding:5px;border:1pxsolid#999;text-align:center;font-family:"Roboto","sans-serif";line-height:30px;padding-left:10px;}#floating-panel{margin-left:-100px;}
<html>
<head>
<title>Overlays Within Street View</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="floating-panel">
<input type="button" value="Toggle Street View" id="toggle" />
</div>
<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/javascript/load-maps-js-api
for more information.
-->
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&libraries=marker&v=weekly"
defer
></script>
</body>
</html>
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[[["\u003cp\u003eThis example demonstrates displaying markers for various points of interest around Astor Place, New York City, on a Google Map.\u003c/p\u003e\n"],["\u003cp\u003eIt features a toggle button that switches to Street View, where the same markers are overlaid on the panoramic imagery.\u003c/p\u003e\n"],["\u003cp\u003eThe code utilizes the Google Maps JavaScript API to create the map, markers, and Street View panorama, along with event listeners for user interaction.\u003c/p\u003e\n"],["\u003cp\u003eThe sample code is provided in both JavaScript and TypeScript, with instructions for running it locally using Git and Node.js or trying it online via JSFiddle and Google Cloud Shell.\u003c/p\u003e\n"]]],["This code creates a Google Map centered on Astor Place, NYC, with markers for a cafe, bank, and bus stop, each using custom icons. An event listener toggles Street View on and off. The Street View panorama defaults to Astor Place with a set heading and pitch. The CSS styles the map and a floating panel with the toggle button, and the HTML includes the map container, button, and links the CSS and JS files.\n"],null,["# Overlays Within Street View\n\nThis example creates a map that displays markers to denote various locations\naround Astor Place, New York City. It includes a toggle to switch to Street\nView, where the same markers are visible.\n\nRead the\n[documentation](/maps/documentation/javascript/streetview#StreetViewOverlays). \n\n### TypeScript\n\n```typescript\nlet panorama: google.maps.StreetViewPanorama;\n\nfunction initMap(): void {\n const astorPlace = { lat: 40.729884, lng: -73.990988 };\n\n // Set up the map\n const map = new google.maps.Map(\n document.getElementById(\"map\") as HTMLElement,\n {\n center: astorPlace,\n zoom: 18,\n streetViewControl: false,\n }\n );\n\n document\n .getElementById(\"toggle\")!\n .addEventListener(\"click\", toggleStreetView);\n\n const cafeIcon = document.createElement(\"img\");\n cafeIcon.src = \"https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg\";\n\n const dollarIcon = document.createElement(\"img\");\n dollarIcon.src = \"https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg\";\n\n const busIcon = document.createElement(\"img\");\n busIcon.src = \"https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg\";\n\n\n // Set up the markers on the map\n const cafeMarker = new google.maps.Marker({\n position: { lat: 40.730031, lng: -73.991428 },\n map,\n title: \"Cafe\",\n icon: cafeIcon.src,\n });\n\n const bankMarker = new google.maps.Marker({\n position: { lat: 40.729681, lng: -73.991138 },\n map,\n title: \"Bank\",\n icon: dollarIcon.src,\n });\n\n const busMarker = new google.maps.Marker({\n position: { lat: 40.729559, lng: -73.990741 },\n map,\n title: \"Bus Stop\",\n icon: busIcon.src,\n });\n\n // We get the map's default panorama and set up some defaults.\n // Note that we don't yet set it visible.\n panorama = map.getStreetView()!; // TODO fix type\n panorama.setPosition(astorPlace);\n panorama.setPov(\n /** @type {google.maps.StreetViewPov} */ {\n heading: 265,\n pitch: 0,\n }\n );\n}\n\nfunction toggleStreetView(): void {\n const toggle = panorama.getVisible();\n\n if (toggle == false) {\n panorama.setVisible(true);\n } else {\n panorama.setVisible(false);\n }\n}\n\ndeclare global {\n interface Window {\n initMap: () =\u003e void;\n }\n}\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/samples/streetview-overlays/index.ts#L8-L86\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\n### JavaScript\n\n```javascript\nlet panorama;\n\nfunction initMap() {\n const astorPlace = { lat: 40.729884, lng: -73.990988 };\n // Set up the map\n const map = new google.maps.Map(document.getElementById(\"map\"), {\n center: astorPlace,\n zoom: 18,\n streetViewControl: false,\n });\n\n document.getElementById(\"toggle\").addEventListener(\"click\", toggleStreetView);\n\n const cafeIcon = document.createElement(\"img\");\n\n cafeIcon.src =\n \"https://developers.google.com/maps/documentation/javascript/examples/full/images/cafe_icon.svg\";\n\n const dollarIcon = document.createElement(\"img\");\n\n dollarIcon.src =\n \"https://developers.google.com/maps/documentation/javascript/examples/full/images/bank_icon.svg\";\n\n const busIcon = document.createElement(\"img\");\n\n busIcon.src =\n \"https://developers.google.com/maps/documentation/javascript/examples/full/images/bus_icon.svg\";\n\n // Set up the markers on the map\n const cafeMarker = new google.maps.Marker({\n position: { lat: 40.730031, lng: -73.991428 },\n map,\n title: \"Cafe\",\n icon: cafeIcon.src,\n });\n const bankMarker = new google.maps.Marker({\n position: { lat: 40.729681, lng: -73.991138 },\n map,\n title: \"Bank\",\n icon: dollarIcon.src,\n });\n const busMarker = new google.maps.Marker({\n position: { lat: 40.729559, lng: -73.990741 },\n map,\n title: \"Bus Stop\",\n icon: busIcon.src,\n });\n\n // We get the map's default panorama and set up some defaults.\n // Note that we don't yet set it visible.\n panorama = map.getStreetView(); // TODO fix type\n panorama.setPosition(astorPlace);\n panorama.setPov(\n /** @type {google.maps.StreetViewPov} */ {\n heading: 265,\n pitch: 0,\n },\n );\n}\n\nfunction toggleStreetView() {\n const toggle = panorama.getVisible();\n\n if (toggle == false) {\n panorama.setVisible(true);\n } else {\n panorama.setVisible(false);\n }\n}\n\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/streetview-overlays/docs/index.js#L7-L77\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n\n### CSS\n\n```css\n/* \n * Always set the map height explicitly to define the size of the div element\n * that contains the map. \n */\n#map {\n height: 100%;\n}\n\n/* \n * Optional: Makes the sample page fill the window. \n */\nhtml,\nbody {\n height: 100%;\n margin: 0;\n padding: 0;\n}\n\n#floating-panel {\n position: absolute;\n top: 10px;\n left: 25%;\n z-index: 5;\n background-color: #fff;\n padding: 5px;\n border: 1px solid #999;\n text-align: center;\n font-family: \"Roboto\", \"sans-serif\";\n line-height: 30px;\n padding-left: 10px;\n}\n\n#floating-panel {\n margin-left: -100px;\n}\nhttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/streetview-overlays/docs/style.css#L7-L42\n```\n\n### HTML\n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003eOverlays Within Street View\u003c/title\u003e\n\n \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" /\u003e\n \u003cscript type=\"module\" src=\"./index.js\"\u003e\u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"floating-panel\"\u003e\n \u003cinput type=\"button\" value=\"Toggle Street View\" id=\"toggle\" /\u003e\n \u003c/div\u003e\n \u003cdiv id=\"map\"\u003e\u003c/div\u003e\n\n \u003c!-- \n The `defer` attribute causes the script to execute after the full HTML\n document has been parsed. For non-blocking uses, avoiding race conditions,\n and consistent behavior across browsers, consider loading using Promises. See\n https://developers.google.com/maps/documentation/javascript/load-maps-js-api\n for more information.\n --\u003e\n \u003cscript\n src=\"https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&libraries=marker&v=weekly\"\n defer\n \u003e\u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003ehttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/streetview-overlays/docs/index.html#L8-L33\n```\n\n### Try Sample\n\n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps/js-samples/tree/master/dist/samples/streetview-overlays/jsfiddle) [Google Cloud Shell](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fgooglemaps%2Fjs-samples&cloudshell_git_branch=sample-streetview-overlays&cloudshell_tutorial=cloud_shell_instructions.md&cloudshell_workspace=.)\n\n### Clone Sample\n\n\nGit and Node.js are required to run this sample locally. Follow these [instructions](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install Node.js and NPM. The following commands clone, install dependencies and start the sample application. \n\n git clone -b sample-streetview-overlays https://github.com/googlemaps/js-samples.git\n cd js-samples\n npm i\n npm start\n\n\nOther samples can be tried by switching to any branch beginning with `sample-`\u003cvar translate=\"no\"\u003eSAMPLE_NAME\u003c/var\u003e. \n\n git checkout sample-\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nx\"\u003eSAMPLE_NAME\u003c/span\u003e\u003c/var\u003e\n npm i\n npm start"]]