Skip to content

Commit 3a1c228

Browse files
authored
feat: Adds new samples for AI-powered summaries. (#994)
* feat: Adds new samples for AI-powered summaries. * Swap order of neighborhood and review summary sections * Disable StreetView and FullScreen UI controls * revert previous change I accidentally updated the wrong file * Update map options to hide controls Disable street view and fullscreen controls on the map. * Modify active tab button styles in style.css Updated active tab button styles for better visibility. * Modify map options and enhance place detail display * Adds click event for marker to display info window. * Adds HTML for "report an issue" link. * Add flag content link to index.html Added a flag content link to the AI summaries page. * Add flag URL support to summary tabs * Add summary panel and tab navigation styles Added styles for the summary panel and tab navigation. * Remove border-top from flag-content-link style
1 parent cae28d3 commit 3a1c228

File tree

12 files changed

+851
-0
lines changed

12 files changed

+851
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Google Maps JavaScript Sample
2+
3+
## ai-powered-summaries-basic
4+
5+
The ai-powered-summaries-basic sample demonstrates how to retrieve AI-powered summaries.
6+
7+
Follow these instructions to set up and run ai-powered-summaries-basic sample on your local computer.
8+
9+
## Setup
10+
11+
### Before starting run:
12+
13+
`npm i`
14+
15+
### Run an example on a local web server
16+
17+
First `cd` to the folder for the sample to run, then:
18+
19+
`npm start`
20+
21+
### Build an individual example
22+
23+
From `samples/`:
24+
25+
`npm run build --workspace=ai-powered-summaries-basic/`
26+
27+
### Build all of the examples.
28+
29+
From `samples/`:
30+
31+
`npm run build-all`
32+
33+
## Feedback
34+
35+
For feedback related to this sample, please open a new issue on
36+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<!--
3+
@license
4+
Copyright 2025 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_ai_powered_summaries_basic] -->
8+
<html>
9+
<head>
10+
<title>AI-powered Summaries Basic Sample</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
<!-- prettier-ignore -->
15+
<script>(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))})
16+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
17+
</head>
18+
<body>
19+
<gmp-map
20+
center="32.7360353,-117.1509849"
21+
zoom="14"
22+
map-id="DEMO_MAP_ID">
23+
</gmp-map>
24+
</body>
25+
</html>
26+
<!-- [END maps_ai_powered_summaries_basic] -->
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_ai_powered_summaries_basic]
8+
const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
9+
let innerMap;
10+
let infoWindow;
11+
12+
async function initMap() {
13+
const { Map, InfoWindow } = (await google.maps.importLibrary(
14+
'maps'
15+
)) as google.maps.MapsLibrary;
16+
17+
innerMap = mapElement.innerMap;
18+
innerMap.setOptions({
19+
mapTypeControl: false
20+
});
21+
22+
infoWindow = new InfoWindow();
23+
getPlaceDetails();
24+
}
25+
26+
async function getPlaceDetails() {
27+
// Request needed libraries.
28+
const [ {AdvancedMarkerElement}, { Place } ] = await Promise.all([
29+
google.maps.importLibrary('marker') as Promise<google.maps.MarkerLibrary>,
30+
google.maps.importLibrary('places') as Promise<google.maps.PlacesLibrary>,
31+
]);
32+
33+
// [START maps_ai_powered_summaries_basic_placeid]
34+
// Use place ID to create a new Place instance.
35+
const place = new Place({
36+
id: 'ChIJzzc-aWUM3IARPOQr9sA6vfY', // San Diego Botanic Garden
37+
});
38+
// [END maps_ai_powered_summaries_basic_placeid]
39+
40+
// Call fetchFields, passing the needed data fields.
41+
// [START maps_ai_powered_summaries_basic_fetchfields]
42+
await place.fetchFields({
43+
fields: [
44+
'displayName',
45+
'formattedAddress',
46+
'location',
47+
'generativeSummary',
48+
],
49+
});
50+
// [END maps_ai_powered_summaries_basic_fetchfields]
51+
52+
// Add an Advanced Marker
53+
const marker = new AdvancedMarkerElement({
54+
map: innerMap,
55+
position: place.location,
56+
title: place.displayName,
57+
});
58+
59+
// Create a content container.
60+
const content = document.createElement('div');
61+
// Populate the container with data.
62+
const address = document.createElement('div');
63+
const summary = document.createElement('div');
64+
const lineBreak = document.createElement('br');
65+
const attribution = document.createElement('div');
66+
67+
// Retrieve the textual data (summary, disclosure, flag URI).
68+
//@ts-ignore
69+
let overviewText = place.generativeSummary.overview ?? 'No summary is available.';
70+
//@ts-ignore
71+
let disclosureText = place.generativeSummary.disclosureText;
72+
//@ts-ignore
73+
let reportingUri = place.generativeSummary.flagContentURI;
74+
75+
// Create HTML for reporting link.
76+
const reportingLink = document.createElement('a');
77+
reportingLink.href = reportingUri;
78+
reportingLink.target = '_blank';
79+
reportingLink.textContent = "Report a problem."
80+
81+
// Add text to layout.
82+
address.textContent = place.formattedAddress ?? '';
83+
summary.textContent = overviewText;
84+
attribution.textContent = `${disclosureText} `;
85+
attribution.appendChild(reportingLink);
86+
87+
content.append(address, lineBreak, summary, lineBreak, attribution);
88+
89+
innerMap.setCenter(place.location);
90+
91+
// Handle marker click.
92+
marker.addListener('gmp-click', () => {
93+
showInfoWindow(marker, place, content);
94+
});
95+
96+
// Display the info window at load time.
97+
showInfoWindow(marker, place, content);
98+
}
99+
100+
function showInfoWindow(marker, place, content) {
101+
// Display an info window.
102+
infoWindow.setHeaderContent(place.displayName);
103+
infoWindow.setContent(content);
104+
infoWindow.open({
105+
anchor: marker,
106+
});
107+
}
108+
109+
initMap();
110+
// [END maps_ai_powered_summaries_basic]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/ai-powered-summaries-basic",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh ai-powered-summaries-basic && bash ../app.sh ai-powered-summaries-basic && bash ../docs.sh ai-powered-summaries-basic && npm run build:vite --workspace=. && bash ../dist.sh ai-powered-summaries-basic",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --base './' && vite",
8+
"build:vite": "vite build --base './'",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
13+
}
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_ai_powered_summaries_basic] */
7+
/*
8+
* Always set the map height explicitly to define the size of the div element
9+
* that contains the map.
10+
*/
11+
#map {
12+
height: 100%;
13+
}
14+
15+
/*
16+
* Optional: Makes the sample page fill the window.
17+
*/
18+
html,
19+
body {
20+
height: 100%;
21+
margin: 0;
22+
padding: 0;
23+
}
24+
25+
/* [END maps_ai_powered_summaries_basic] */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"strict": true,
6+
"noImplicitAny": false,
7+
"lib": [
8+
"es2015",
9+
"esnext",
10+
"es6",
11+
"dom",
12+
"dom.iterable"
13+
],
14+
"moduleResolution": "Node",
15+
"jsx": "preserve"
16+
}
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Google Maps JavaScript Sample
2+
3+
## ai-powered-summaries
4+
5+
The ai-powered-summaries sample demonstrates how to show AI-powered summaries a map.
6+
7+
Follow these instructions to set up and run ai-powered-summaries sample on your local computer.
8+
9+
## Setup
10+
11+
### Before starting run:
12+
13+
`npm i`
14+
15+
### Run an example on a local web server
16+
17+
First `cd` to the folder for the sample to run, then:
18+
19+
`npm start`
20+
21+
### Build an individual example
22+
23+
From `samples/`:
24+
25+
`npm run build --workspace=ai-powered-summaries/`
26+
27+
### Build all of the examples.
28+
29+
From `samples/`:
30+
31+
`npm run build-all`
32+
33+
## Feedback
34+
35+
For feedback related to this sample, please open a new issue on
36+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<!--
3+
@license
4+
Copyright 2025 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_ai_powered_summaries] -->
8+
<html>
9+
<head>
10+
<title>AI Place Summaries</title>
11+
<link rel="stylesheet" type="text/css" href="./style.css" />
12+
<script type="module" src="./index.js"></script>
13+
<!-- prettier-ignore -->
14+
<script>(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))})
15+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
16+
</head>
17+
<body>
18+
<gmp-map center="37.805, -122.425" zoom="14" map-id="DEMO_MAP_ID">
19+
<!-- Search Input Card -->
20+
<div
21+
class="place-autocomplete-card"
22+
slot="control-inline-start-block-start">
23+
<p>Search for a place with AI summaries:</p>
24+
<gmp-place-autocomplete></gmp-place-autocomplete>
25+
</div>
26+
27+
<!-- Summary text panel (initially hidden) -->
28+
<div
29+
id="summary-panel"
30+
class="summary-card hidden"
31+
slot="control-inline-end-block-start">
32+
<div id="place-header">
33+
<h2 id="place-name"></h2>
34+
<p id="place-address"></p>
35+
</div>
36+
37+
<!-- Tabs for toggling summary types -->
38+
<div class="tab-container" id="tab-container"></div>
39+
40+
<!-- Content display area -->
41+
<div id="summary-content" class="content-area"></div>
42+
43+
<!-- Legal/AI Disclosure -->
44+
<div id="ai-disclosure" class="disclosure-footer"></div>
45+
46+
<!-- Flag content link -->
47+
<a id="flag-content-link" class="flag-content-link"></a>
48+
</div>
49+
</gmp-map>
50+
</body>
51+
</html>
52+
<!-- [END maps_ai_powered_summaries] -->

0 commit comments

Comments
 (0)