Skip to content

Commit cfbc063

Browse files
committed
feat: Adds new samples for AI-powered summaries.
1 parent b14d054 commit cfbc063

File tree

12 files changed

+668
-0
lines changed

12 files changed

+668
-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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
infoWindow = new InfoWindow();
19+
getPlaceDetails();
20+
}
21+
22+
async function getPlaceDetails() {
23+
// Request needed libraries.
24+
const [ {AdvancedMarkerElement}, { Place } ] = await Promise.all([
25+
google.maps.importLibrary('marker') as Promise<google.maps.MarkerLibrary>,
26+
google.maps.importLibrary('places') as Promise<google.maps.PlacesLibrary>,
27+
]);
28+
29+
// [START maps_ai_powered_summaries_basic_placeid]
30+
// Use place ID to create a new Place instance.
31+
const place = new Place({
32+
id: 'ChIJzzc-aWUM3IARPOQr9sA6vfY', // San Diego Botanic Garden
33+
});
34+
// [END maps_ai_powered_summaries_basic_placeid]
35+
36+
// Call fetchFields, passing the needed data fields.
37+
// [START maps_ai_powered_summaries_basic_fetchfields]
38+
await place.fetchFields({
39+
fields: [
40+
'displayName',
41+
'formattedAddress',
42+
'location',
43+
'generativeSummary',
44+
],
45+
});
46+
// [END maps_ai_powered_summaries_basic_fetchfields]
47+
48+
// Add an Advanced Marker
49+
const marker = new AdvancedMarkerElement({
50+
map: innerMap,
51+
position: place.location,
52+
title: place.displayName,
53+
});
54+
55+
// Create a content container.
56+
const content = document.createElement('div');
57+
// Populate the container with data.
58+
const address = document.createElement('div');
59+
const summary = document.createElement('div');
60+
const lineBreak = document.createElement('br');
61+
62+
// Retrieve the summary text and disclosure text.
63+
//@ts-ignore
64+
let overviewText = place.generativeSummary.overview ?? 'No summary is available.';
65+
//@ts-ignore
66+
let disclosureText = place.generativeSummary.disclosureText ?? '';
67+
68+
address.textContent = place.formattedAddress ?? '';
69+
summary.textContent = `${overviewText} [${disclosureText}]`;
70+
content.append(address, lineBreak, summary);;
71+
72+
innerMap.setCenter(place.location);
73+
74+
// Display an info window.
75+
infoWindow.setHeaderContent(place.displayName);
76+
infoWindow.setContent(content);
77+
infoWindow.open({
78+
anchor: marker,
79+
});
80+
}
81+
82+
initMap();
83+
// [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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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><!-- prettier-ignore -->
13+
<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))})
14+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
15+
</head>
16+
<body>
17+
<gmp-map center="37.805, -122.425" zoom="14" map-id="DEMO_MAP_ID">
18+
<!-- Search Input Card -->
19+
<div
20+
class="place-autocomplete-card"
21+
slot="control-inline-start-block-start">
22+
<p>Search for a place with AI summaries:</p>
23+
<gmp-place-autocomplete></gmp-place-autocomplete>
24+
</div>
25+
26+
<!-- Summary text panel (initially hidden) -->
27+
<div
28+
id="summary-panel"
29+
class="summary-card hidden"
30+
slot="control-inline-end-block-start">
31+
<div id="place-header">
32+
<h2 id="place-name"></h2>
33+
<p id="place-address"></p>
34+
</div>
35+
36+
<!-- Tabs for toggling summary types -->
37+
<div class="tab-container" id="tab-container"></div>
38+
39+
<!-- Content display area -->
40+
<div id="summary-content" class="content-area"></div>
41+
42+
<!-- Legal/AI Disclosure -->
43+
<div id="ai-disclosure" class="disclosure-footer"></div>
44+
</div>
45+
</gmp-map>
46+
</body>
47+
</html>
48+
<!-- [END maps_ai_powered_summaries] -->

0 commit comments

Comments
 (0)