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
2 changes: 2 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ <h1>Maps JSAPI Samples</h1>
<li><a href='/samples/advanced-markers-html-simple/dist'>advanced-markers-html-simple</a></li>
<li><a href='/samples/advanced-markers-simple/dist'>advanced-markers-simple</a></li>
<li><a href='/samples/advanced-markers-zoom/dist'>advanced-markers-zoom</a></li>
<li><a href='/samples/ai-powered-summaries/dist'>ai-powered-summaries</a></li>
<li><a href='/samples/ai-powered-summaries-basic/dist'>ai-powered-summaries-basic</a></li>
<li><a href='/samples/boundaries-choropleth/dist'>boundaries-choropleth</a></li>
<li><a href='/samples/boundaries-click/dist'>boundaries-click</a></li>
<li><a href='/samples/boundaries-simple/dist'>boundaries-simple</a></li>
Expand Down
13 changes: 13 additions & 0 deletions dist/samples/ai-powered-summaries-basic/app/.eslintsrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-this-alias": 1,
"@typescript-eslint/no-empty-function": 1,
"@typescript-eslint/explicit-module-boundary-types": 1,
"@typescript-eslint/no-unused-vars": 1
}
}
36 changes: 36 additions & 0 deletions dist/samples/ai-powered-summaries-basic/app/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 dist/samples/ai-powered-summaries-basic/app/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 dist/samples/ai-powered-summaries-basic/app/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 dist/samples/ai-powered-summaries-basic/app/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 dist/samples/ai-powered-summaries-basic/app/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 dist/samples/ai-powered-summaries-basic/app/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"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#map{height:100%}html,body{height:100%;margin:0;padding:0}
26 changes: 26 additions & 0 deletions dist/samples/ai-powered-summaries-basic/dist/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>

<!-- 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>
<script type="module" crossorigin src="./assets/index-CFZ6i2WL.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-DWepjxzn.css">
</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] -->
26 changes: 26 additions & 0 deletions dist/samples/ai-powered-summaries-basic/docs/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] -->
Loading