Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions samples/ai-powered-summaries-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Google Maps JavaScript Sample

## ai-powered-summaries-basic

The ai-powered-summaries-basic sample demonstrates how to retrieve AI-powered summaries.

Follow these instructions to set up and run ai-powered-summaries-basic sample on your local computer.

## Setup

### Before starting run:

`npm i`

### Run an example on a local web server

First `cd` to the folder for the sample to run, then:

`npm start`

### Build an individual example

From `samples/`:

`npm run build --workspace=ai-powered-summaries-basic/`

### Build all of the examples.

From `samples/`:

`npm run build-all`

## Feedback

For feedback related to this sample, please open a new issue on
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
26 changes: 26 additions & 0 deletions samples/ai-powered-summaries-basic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_ai_powered_summaries_basic] -->
<html>
<head>
<title>AI-powered Summaries Basic Sample</title>

<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
<!-- prettier-ignore -->
<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))})
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
</head>
<body>
<gmp-map
center="32.7360353,-117.1509849"
zoom="14"
map-id="DEMO_MAP_ID">
</gmp-map>
</body>
</html>
<!-- [END maps_ai_powered_summaries_basic] -->
110 changes: 110 additions & 0 deletions samples/ai-powered-summaries-basic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

// [START maps_ai_powered_summaries_basic]
const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
let innerMap;
let infoWindow;

async function initMap() {
const { Map, InfoWindow } = (await google.maps.importLibrary(
'maps'
)) as google.maps.MapsLibrary;

innerMap = mapElement.innerMap;
innerMap.setOptions({
mapTypeControl: false
});

infoWindow = new InfoWindow();
getPlaceDetails();
}

async function getPlaceDetails() {
// Request needed libraries.
const [ {AdvancedMarkerElement}, { Place } ] = await Promise.all([
google.maps.importLibrary('marker') as Promise<google.maps.MarkerLibrary>,
google.maps.importLibrary('places') as Promise<google.maps.PlacesLibrary>,
]);

// [START maps_ai_powered_summaries_basic_placeid]
// Use place ID to create a new Place instance.
const place = new Place({
id: 'ChIJzzc-aWUM3IARPOQr9sA6vfY', // San Diego Botanic Garden
});
// [END maps_ai_powered_summaries_basic_placeid]

// Call fetchFields, passing the needed data fields.
// [START maps_ai_powered_summaries_basic_fetchfields]
await place.fetchFields({
fields: [
'displayName',
'formattedAddress',
'location',
'generativeSummary',
],
});
// [END maps_ai_powered_summaries_basic_fetchfields]

// Add an Advanced Marker
const marker = new AdvancedMarkerElement({
map: innerMap,
position: place.location,
title: place.displayName,
});

// Create a content container.
const content = document.createElement('div');
// Populate the container with data.
const address = document.createElement('div');
const summary = document.createElement('div');
const lineBreak = document.createElement('br');
const attribution = document.createElement('div');

// Retrieve the textual data (summary, disclosure, flag URI).
//@ts-ignore
let overviewText = place.generativeSummary.overview ?? 'No summary is available.';
//@ts-ignore
let disclosureText = place.generativeSummary.disclosureText;
//@ts-ignore
let reportingUri = place.generativeSummary.flagContentURI;

// Create HTML for reporting link.
const reportingLink = document.createElement('a');
reportingLink.href = reportingUri;
reportingLink.target = '_blank';
reportingLink.textContent = "Report a problem."

// Add text to layout.
address.textContent = place.formattedAddress ?? '';
summary.textContent = overviewText;
attribution.textContent = `${disclosureText} `;
attribution.appendChild(reportingLink);

content.append(address, lineBreak, summary, lineBreak, attribution);

innerMap.setCenter(place.location);

// Handle marker click.
marker.addListener('gmp-click', () => {
showInfoWindow(marker, place, content);
});

// Display the info window at load time.
showInfoWindow(marker, place, content);
}

function showInfoWindow(marker, place, content) {
// Display an info window.
infoWindow.setHeaderContent(place.displayName);
infoWindow.setContent(content);
infoWindow.open({
anchor: marker,
});
}

initMap();
// [END maps_ai_powered_summaries_basic]
14 changes: 14 additions & 0 deletions samples/ai-powered-summaries-basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@js-api-samples/ai-powered-summaries-basic",
"version": "1.0.0",
"scripts": {
"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",
"test": "tsc && npm run build:vite --workspace=.",
"start": "tsc && vite build --base './' && vite",
"build:vite": "vite build --base './'",
"preview": "vite preview"
},
"dependencies": {

}
}
25 changes: 25 additions & 0 deletions samples/ai-powered-summaries-basic/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/* [START maps_ai_powered_summaries_basic] */
/*
* 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;
}

/* [END maps_ai_powered_summaries_basic] */
17 changes: 17 additions & 0 deletions samples/ai-powered-summaries-basic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"strict": true,
"noImplicitAny": false,
"lib": [
"es2015",
"esnext",
"es6",
"dom",
"dom.iterable"
],
"moduleResolution": "Node",
"jsx": "preserve"
}
}
36 changes: 36 additions & 0 deletions samples/ai-powered-summaries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Google Maps JavaScript Sample

## ai-powered-summaries

The ai-powered-summaries sample demonstrates how to show AI-powered summaries a map.

Follow these instructions to set up and run ai-powered-summaries sample on your local computer.

## Setup

### Before starting run:

`npm i`

### Run an example on a local web server

First `cd` to the folder for the sample to run, then:

`npm start`

### Build an individual example

From `samples/`:

`npm run build --workspace=ai-powered-summaries/`

### Build all of the examples.

From `samples/`:

`npm run build-all`

## Feedback

For feedback related to this sample, please open a new issue on
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
52 changes: 52 additions & 0 deletions samples/ai-powered-summaries/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_ai_powered_summaries] -->
<html>
<head>
<title>AI Place Summaries</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
<!-- prettier-ignore -->
<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))})
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
</head>
<body>
<gmp-map center="37.805, -122.425" zoom="14" map-id="DEMO_MAP_ID">
<!-- Search Input Card -->
<div
class="place-autocomplete-card"
slot="control-inline-start-block-start">
<p>Search for a place with AI summaries:</p>
<gmp-place-autocomplete></gmp-place-autocomplete>
</div>

<!-- Summary text panel (initially hidden) -->
<div
id="summary-panel"
class="summary-card hidden"
slot="control-inline-end-block-start">
<div id="place-header">
<h2 id="place-name"></h2>
<p id="place-address"></p>
</div>

<!-- Tabs for toggling summary types -->
<div class="tab-container" id="tab-container"></div>

<!-- Content display area -->
<div id="summary-content" class="content-area"></div>

<!-- Legal/AI Disclosure -->
<div id="ai-disclosure" class="disclosure-footer"></div>

<!-- Flag content link -->
<a id="flag-content-link" class="flag-content-link"></a>
</div>
</gmp-map>
</body>
</html>
<!-- [END maps_ai_powered_summaries] -->
Loading