Skip to content

Commit 2ef4f80

Browse files
feat(samples): add advanced place details and search samples (#1647)
* feat(samples): add advanced place details and search samples * fix(samples): add v=alpha to preview advanced place UI elements * fix(samples): change v=alpha to v=beta for advanced place elements * fix(samples): explicitly list gmp-place-name so Place titles render in advanced details * feat(samples): deliberately omit gmp-place-name in advanced place details payload * style(samples): format ui-kit-place-details-demo files to satisfy prettier * chore(samples): remove mistakenly committed ui-kit-place-details-demo * feat(samples): add advanced place list demo * fix(samples): import places API explicitly in advanced place list * fix(samples): substitute missing dummy PRNs with known valid Place IDs for advanced place list demo * fix(samples): change comma-separated places list to space-separated as per AdvancedPlaceListElement parser behavior * fix(samples): populate Advanced Place List demo with top 5 global landmarks rather than dummy placeholder data * chore: enforce strict typescript types; minor fixes. Change-Id: I8fcdb3b6d1babe4b18daa0fcd3c903c39d812332 * chore: one last prettification Change-Id: I86ce791b91ada99b429dfc1ab08a8e917ed5b3bb * fix(samples): Add <gmp-place-name> to advanced samples as requested * fix(samples): omit <gmp-place-name> on advanced place search nearby demo to illustrate element suppression --------- Co-authored-by: William French <dubnewt@gmail.com>
1 parent 202a68a commit 2ef4f80

31 files changed

Lines changed: 1302 additions & 0 deletions

File tree

package-lock.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Google Maps JavaScript Sample
2+
3+
## ui-kit-advanced-place-details-compact
4+
5+
The ui-kit-advanced-place-details-compact sample demonstrates how to use the UI Kit for Place Details in a compact layout.
6+
7+
Follow these instructions to set up and run ui-kit-advanced-place-details-compact 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=ui-kit-advanced-place-details-compact/`
26+
27+
### Build all of the examples.
28+
29+
From `samples/`:
30+
`$npm run build-all`
31+
32+
## Feedback
33+
34+
For feedback related to this sample, please open a new issue on
35+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<!--
2+
@license
3+
Copyright 2026 Google LLC. All Rights Reserved.
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
<!--[START maps_ui_kit_advanced_place_details_compact] -->
7+
<!doctype html>
8+
<html>
9+
<head>
10+
<title>Place Details Compact with Google Maps</title>
11+
<meta charset="utf-8" />
12+
<link rel="stylesheet" type="text/css" href="style.css" />
13+
<script type="module" src="./index.js"></script>
14+
<script>
15+
// prettier-ignore
16+
(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))})({
17+
key: "GOOGLE_MAPS_API_KEY",
18+
v: "beta"
19+
});
20+
</script>
21+
</head>
22+
<body>
23+
<div class="container">
24+
<!-- map-id is required to use Advanced Markers. See https://developers.google.com/maps/documentation/javascript/map-ids/mapid-over. -->
25+
<gmp-map zoom="17" map-id="DEMO_MAP_ID">
26+
<gmp-advanced-marker></gmp-advanced-marker>
27+
</gmp-map>
28+
</div>
29+
<!--
30+
The gmp-advanced-place-details-compact element is styled inline because it is
31+
conditionally rendered and moved into the info window, which is
32+
part of the map's shadow DOM.
33+
-->
34+
<!--[START maps_ui_kit_advanced_place_details_compact_map_setup] -->
35+
<gmp-advanced-place-details-compact
36+
orientation="horizontal"
37+
truncation-preferred
38+
style="
39+
width: 400px;
40+
padding: 0;
41+
margin: 0;
42+
border: none;
43+
background-color: transparent;
44+
color-scheme: light;
45+
">
46+
<gmp-place-details-place-request
47+
place="places/ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>
48+
<!--[END maps_ui_kit_advanced_place_details_compact_map_setup] -->
49+
<!--[START maps_ui_kit_advanced_place_details_compact_config] -->
50+
51+
<gmp-place-name></gmp-place-name>
52+
<gmp-place-media lightbox-preferred></gmp-place-media>
53+
<gmp-place-rating></gmp-place-rating>
54+
<gmp-place-type></gmp-place-type>
55+
<gmp-place-price></gmp-place-price>
56+
<gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon>
57+
<gmp-place-open-now-status></gmp-place-open-now-status>
58+
<gmp-place-attribution
59+
light-scheme-color="gray"
60+
dark-scheme-color="white"></gmp-place-attribution>
61+
62+
<!--[END maps_ui_kit_advanced_place_details_compact_config] -->
63+
</gmp-advanced-place-details-compact>
64+
</body>
65+
</html>
66+
<!--[END maps_ui_kit_advanced_place_details_compact] -->
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_ui_kit_advanced_place_details_compact] */
7+
// Use querySelector to select elements for interaction.
8+
/* [START maps_ui_kit_advanced_place_details_compact_query_selector] */
9+
const map = document.querySelector<google.maps.MapElement>('gmp-map')!;
10+
const placeDetails = document.querySelector<
11+
HTMLElement & { place?: google.maps.places.Place }
12+
>('gmp-advanced-place-details-compact')!;
13+
const placeDetailsRequest = document.querySelector<HTMLElement>(
14+
'gmp-place-details-place-request'
15+
)!;
16+
const marker = document.querySelector<google.maps.marker.AdvancedMarkerElement>(
17+
'gmp-advanced-marker'
18+
)!;
19+
/* [END maps_ui_kit_advanced_place_details_compact_query_selector] */
20+
async function init(): Promise<void> {
21+
// Request needed libraries.
22+
void Promise.all([
23+
google.maps.importLibrary('marker'),
24+
google.maps.importLibrary('places'),
25+
]);
26+
const { InfoWindow } = await google.maps.importLibrary('maps');
27+
28+
await window.customElements.whenDefined('gmp-map');
29+
// Set the inner map options.
30+
map.innerMap.setOptions({
31+
mapTypeControl: false,
32+
streetViewControl: false,
33+
});
34+
35+
await window.customElements.whenDefined('gmp-advanced-marker');
36+
marker.collisionBehavior = 'REQUIRED_AND_HIDES_OPTIONAL';
37+
38+
const infoWindow = new InfoWindow();
39+
infoWindow.addListener('close', () => {
40+
marker.position = null;
41+
});
42+
43+
const showInfoWindow = () => {
44+
if (infoWindow.isOpen) return;
45+
infoWindow.setContent(placeDetails);
46+
infoWindow.open({ anchor: marker });
47+
};
48+
49+
placeDetails.addEventListener('gmp-load', () => {
50+
// For the initial load case, with no user click, we fall back to the place's location, and ensure the map has a center set and the InfoWindow is show.
51+
// (The clicked POI LatLng will be a more natural marker position, when available.)
52+
if (!map.center && placeDetails.place?.location) {
53+
map.center = marker.position = placeDetails.place.location;
54+
showInfoWindow();
55+
}
56+
});
57+
58+
/* [START maps_ui_kit_advanced_place_details_compact_event] */
59+
// Add an event listener to handle clicks.
60+
map.innerMap.addListener(
61+
'click',
62+
(event: google.maps.MapMouseEvent | google.maps.IconMouseEvent) => {
63+
event.stop();
64+
65+
if ('placeId' in event && event.placeId) {
66+
// When the user clicks a POI.
67+
marker.position = event.latLng;
68+
placeDetailsRequest.setAttribute(
69+
'place',
70+
`places/${event.placeId}`
71+
);
72+
showInfoWindow();
73+
} else {
74+
// When the user clicks the map (not on a POI).
75+
marker.position = null;
76+
placeDetailsRequest.removeAttribute('place');
77+
console.log('No place was selected.');
78+
}
79+
}
80+
);
81+
}
82+
/* [END maps_ui_kit_advanced_place_details_compact_event] */
83+
void init();
84+
/* [END maps_ui_kit_advanced_place_details_compact] */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@js-api-samples/ui-kit-advanced-place-details-compact",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "bash ../build-single.sh",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --config ../../vite.config.js --base './' && vite --config ../../vite.config.js",
8+
"build:vite": "vite build --config ../../vite.config.js --base './'",
9+
"preview": "vite preview --config ../../vite.config.js"
10+
},
11+
"author": "Google LLC"
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @license
3+
* Copyright 2026 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_ui_kit_place_details_compact] */
7+
/*
8+
* Optional: Makes the sample page fill the window.
9+
*/
10+
html,
11+
body {
12+
height: 100%;
13+
margin: 0;
14+
padding: 0;
15+
}
16+
17+
.container {
18+
display: flex;
19+
height: 100vh;
20+
width: 100%;
21+
}
22+
23+
gmp-map {
24+
flex-grow: 1;
25+
}
26+
/* [END maps_ui_kit_place_details_compact] */
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "."
5+
},
6+
"include": ["./*.ts"]
7+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Google Maps JavaScript Sample
2+
3+
## ui-kit-advanced-place-details
4+
5+
The ui-kit-advanced-place-details sample demonstrates how to use the UI Kit Place Details element.
6+
7+
Follow these instructions to set up and run ui-kit-advanced-place-details 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=ui-kit-advanced-place-details/`
26+
27+
### Build all of the examples.
28+
29+
From `samples/`:
30+
`$npm run build-all`
31+
32+
## Feedback
33+
34+
For feedback related to this sample, please open a new issue on
35+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!--
2+
@license
3+
Copyright 2026 Google LLC. All Rights Reserved.
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
<!--[START maps_ui_kit_advanced_place_details] -->
7+
<!doctype html>
8+
<html>
9+
<head>
10+
<title>Place Details with Google Maps</title>
11+
<meta charset="utf-8" />
12+
<link rel="stylesheet" type="text/css" href="style.css" />
13+
<script type="module" src="./index.js"></script>
14+
<script>
15+
// prettier-ignore
16+
(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))})({
17+
key: "GOOGLE_MAPS_API_KEY",
18+
v: "beta"
19+
});
20+
</script>
21+
</head>
22+
<body>
23+
<!--[START maps_ui_kit_advanced_place_details_map] -->
24+
<div class="container">
25+
<!-- map-id is required to use advanced markers. See https://developers.google.com/maps/documentation/javascript/map-ids/mapid-over. -->
26+
<gmp-map zoom="17" map-id="DEMO_MAP_ID">
27+
<gmp-advanced-marker></gmp-advanced-marker>
28+
</gmp-map>
29+
<div class="ui-panel">
30+
<gmp-advanced-place-details>
31+
<gmp-place-details-place-request
32+
place="places/ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>
33+
34+
<gmp-place-name></gmp-place-name>
35+
<gmp-place-address></gmp-place-address>
36+
<gmp-place-rating></gmp-place-rating>
37+
<gmp-place-type></gmp-place-type>
38+
<gmp-place-price></gmp-place-price>
39+
<gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon>
40+
<gmp-place-opening-hours></gmp-place-opening-hours>
41+
<gmp-place-website></gmp-place-website>
42+
<gmp-place-phone-number></gmp-place-phone-number>
43+
<gmp-place-summary></gmp-place-summary>
44+
<gmp-place-type-specific-highlights></gmp-place-type-specific-highlights>
45+
<gmp-place-review-summary></gmp-place-review-summary>
46+
<gmp-place-reviews></gmp-place-reviews>
47+
<gmp-place-feature-list></gmp-place-feature-list>
48+
</gmp-advanced-place-details>
49+
</div>
50+
</div>
51+
<!--[END maps_ui_kit_advanced_place_details_map] -->
52+
</body>
53+
</html>
54+
<!--[END maps_ui_kit_advanced_place_details] -->

0 commit comments

Comments
 (0)