streetview-events
Sample code supporting Google Maps Platform JavaScript API documentation.
author(s):
Geo Developer IX Documentation Team
HTML
<!doctype html>
<!--
@license
Copyright 2026 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<html>
<head>
<title>Street View Events</title>
<script>
// prettier-ignore
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
});
</script>
</head>
<body>
<div id="pano"></div>
<div id="floating-panel">
<table>
<tr>
<td><b>Position</b></td>
<td id="position-cell"> </td>
</tr>
<tr>
<td><b>POV Heading</b></td>
<td id="heading-cell">165</td>
</tr>
<tr>
<td><b>POV Pitch</b></td>
<td id="pitch-cell">0.0</td>
</tr>
<tr>
<td><b>Pano ID</b></td>
<td id="pano-cell"> </td>
</tr>
</table>
<table id="links_table"></table>
</div>
</body>
</html>
CSS
/**
* @license
* Copyright 2026 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
display: flex;
}
#pano {
flex: 1;
height: 100%;
}
#floating-panel {
flex: 1;
height: 100%;
box-sizing: border-box;
background-color: #fff;
padding: 5px 5px 5px 10px;
text-align: left;
font-family: Roboto, sans-serif;
line-height: 30px;
overflow: auto;
}
JavaScript
'use strict';
/**
* @license
* Copyright 2026 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
async function init() {
// Request needed libraries.
const { StreetViewPanorama } = await google.maps.importLibrary('streetView');
const panoElement = document.getElementById('pano');
const panoCell = document.getElementById('pano-cell');
const linksTable = document.getElementById('links_table');
const positionCell = document.getElementById('position-cell');
const headingCell = document.getElementById('heading-cell');
const pitchCell = document.getElementById('pitch-cell');
const panorama = new StreetViewPanorama(panoElement, {
position: { lat: 37.869, lng: -122.255 },
pov: {
heading: 165,
pitch: 0,
},
visible: true,
});
panorama.addListener('pano_changed', () => {
panoCell.textContent = panorama.getPano();
});
panorama.addListener('links_changed', () => {
linksTable.replaceChildren();
const links = panorama.getLinks();
if (!links) {
return;
}
links.forEach((link, index) => {
if (!link) {
return;
}
const row = document.createElement('tr');
const labelCell = document.createElement('td');
const labelStrong = document.createElement('b');
labelStrong.textContent = `Link: ${String(index)}`;
labelCell.appendChild(labelStrong);
const valueCell = document.createElement('td');
valueCell.textContent = link.description ?? '';
row.appendChild(labelCell);
row.appendChild(valueCell);
linksTable.appendChild(row);
});
});
panorama.addListener('position_changed', () => {
const position = panorama.getPosition();
positionCell.textContent = position ? position.toString() : '';
});
panorama.addListener('pov_changed', () => {
const pov = panorama.getPov();
headingCell.textContent = String(pov.heading);
pitchCell.textContent = String(pov.pitch);
});
}
void...