-
Notifications
You must be signed in to change notification settings - Fork 13
feat(samples): add advanced place details and search samples #1647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7902536
feat(samples): add advanced place details and search samples
ejhaselden 405e849
fix(samples): add v=alpha to preview advanced place UI elements
ejhaselden 21b6e40
fix(samples): change v=alpha to v=beta for advanced place elements
ejhaselden c9c9141
fix(samples): explicitly list gmp-place-name so Place titles render i…
ejhaselden ecce897
Merge branch 'main' into add-advanced-place-elements
ejhaselden e3d008d
feat(samples): deliberately omit gmp-place-name in advanced place det…
ejhaselden 274d8fa
Merge origin/add-advanced-place-elements
ejhaselden a7a2639
style(samples): format ui-kit-place-details-demo files to satisfy pre…
ejhaselden 980161f
chore(samples): remove mistakenly committed ui-kit-place-details-demo
ejhaselden 84a2285
feat(samples): add advanced place list demo
ejhaselden 1926a5c
fix(samples): import places API explicitly in advanced place list
ejhaselden eeeb916
fix(samples): substitute missing dummy PRNs with known valid Place ID…
ejhaselden 23c0d2b
fix(samples): change comma-separated places list to space-separated a…
ejhaselden 246c006
fix(samples): populate Advanced Place List demo with top 5 global lan…
ejhaselden 1541ebf
chore: enforce strict typescript types; minor fixes.
willum070 ed9a932
chore: one last prettification
willum070 e9aeef0
fix(samples): Add <gmp-place-name> to advanced samples as requested
ejhaselden f546796
fix(samples): omit <gmp-place-name> on advanced place search nearby d…
ejhaselden 0db32b5
Merge branch 'main' into add-advanced-place-elements
ejhaselden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Google Maps JavaScript Sample | ||
|
|
||
| ## ui-kit-advanced-place-details-compact | ||
|
|
||
| The ui-kit-advanced-place-details-compact sample demonstrates how to use the UI Kit for Place Details in a compact layout. | ||
|
|
||
| Follow these instructions to set up and run ui-kit-advanced-place-details-compact 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=ui-kit-advanced-place-details-compact/` | ||
|
|
||
| ### 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <!-- | ||
| @license | ||
| Copyright 2026 Google LLC. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
| <!--[START maps_ui_kit_advanced_place_details_compact] --> | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>Place Details Compact with Google Maps</title> | ||
| <meta charset="utf-8" /> | ||
| <link rel="stylesheet" type="text/css" href="style.css" /> | ||
| <script type="module" src="./index.js"></script> | ||
| <script> | ||
| // prettier-ignore | ||
| (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: "GOOGLE_MAPS_API_KEY", | ||
| v: "beta" | ||
| }); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div class="container"> | ||
| <!-- map-id is required to use Advanced Markers. See https://developers.google.com/maps/documentation/javascript/map-ids/mapid-over. --> | ||
| <gmp-map zoom="17" map-id="DEMO_MAP_ID"> | ||
| <gmp-advanced-marker></gmp-advanced-marker> | ||
| </gmp-map> | ||
| </div> | ||
| <!-- | ||
| The gmp-advanced-place-details-compact element is styled inline because it is | ||
| conditionally rendered and moved into the info window, which is | ||
| part of the map's shadow DOM. | ||
| --> | ||
| <!--[START maps_ui_kit_advanced_place_details_compact_map_setup] --> | ||
| <gmp-advanced-place-details-compact | ||
| orientation="horizontal" | ||
| truncation-preferred | ||
| style=" | ||
| width: 400px; | ||
| padding: 0; | ||
| margin: 0; | ||
| border: none; | ||
| background-color: transparent; | ||
| color-scheme: light; | ||
| "> | ||
| <gmp-place-details-place-request | ||
| place="places/ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request> | ||
| <!--[END maps_ui_kit_advanced_place_details_compact_map_setup] --> | ||
| <!--[START maps_ui_kit_advanced_place_details_compact_config] --> | ||
|
|
||
| <gmp-place-name></gmp-place-name> | ||
| <gmp-place-media lightbox-preferred></gmp-place-media> | ||
|
ejhaselden marked this conversation as resolved.
|
||
| <gmp-place-rating></gmp-place-rating> | ||
| <gmp-place-type></gmp-place-type> | ||
| <gmp-place-price></gmp-place-price> | ||
| <gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon> | ||
| <gmp-place-open-now-status></gmp-place-open-now-status> | ||
| <gmp-place-attribution | ||
| light-scheme-color="gray" | ||
| dark-scheme-color="white"></gmp-place-attribution> | ||
|
|
||
| <!--[END maps_ui_kit_advanced_place_details_compact_config] --> | ||
| </gmp-advanced-place-details-compact> | ||
| </body> | ||
| </html> | ||
| <!--[END maps_ui_kit_advanced_place_details_compact] --> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * @license | ||
| * Copyright 2025 Google LLC. All Rights Reserved. | ||
|
ejhaselden marked this conversation as resolved.
|
||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /* [START maps_ui_kit_advanced_place_details_compact] */ | ||
| // Use querySelector to select elements for interaction. | ||
| /* [START maps_ui_kit_advanced_place_details_compact_query_selector] */ | ||
| const map = document.querySelector<google.maps.MapElement>('gmp-map')!; | ||
| const placeDetails = document.querySelector< | ||
| HTMLElement & { place?: google.maps.places.Place } | ||
| >('gmp-advanced-place-details-compact')!; | ||
| const placeDetailsRequest = document.querySelector<HTMLElement>( | ||
| 'gmp-place-details-place-request' | ||
| )!; | ||
| const marker = document.querySelector<google.maps.marker.AdvancedMarkerElement>( | ||
| 'gmp-advanced-marker' | ||
| )!; | ||
| /* [END maps_ui_kit_advanced_place_details_compact_query_selector] */ | ||
| async function init(): Promise<void> { | ||
| // Request needed libraries. | ||
| void Promise.all([ | ||
| google.maps.importLibrary('marker'), | ||
| google.maps.importLibrary('places'), | ||
| ]); | ||
| const { InfoWindow } = await google.maps.importLibrary('maps'); | ||
|
|
||
| await window.customElements.whenDefined('gmp-map'); | ||
| // Set the inner map options. | ||
| map.innerMap.setOptions({ | ||
| mapTypeControl: false, | ||
| streetViewControl: false, | ||
| }); | ||
|
|
||
| await window.customElements.whenDefined('gmp-advanced-marker'); | ||
| marker.collisionBehavior = 'REQUIRED_AND_HIDES_OPTIONAL'; | ||
|
|
||
| const infoWindow = new InfoWindow(); | ||
| infoWindow.addListener('close', () => { | ||
| marker.position = null; | ||
| }); | ||
|
|
||
| const showInfoWindow = () => { | ||
| if (infoWindow.isOpen) return; | ||
| infoWindow.setContent(placeDetails); | ||
| infoWindow.open({ anchor: marker }); | ||
| }; | ||
|
|
||
| placeDetails.addEventListener('gmp-load', () => { | ||
| // 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. | ||
| // (The clicked POI LatLng will be a more natural marker position, when available.) | ||
| if (!map.center && placeDetails.place?.location) { | ||
| map.center = marker.position = placeDetails.place.location; | ||
| showInfoWindow(); | ||
| } | ||
| }); | ||
|
|
||
| /* [START maps_ui_kit_advanced_place_details_compact_event] */ | ||
| // Add an event listener to handle clicks. | ||
| map.innerMap.addListener( | ||
| 'click', | ||
| (event: google.maps.MapMouseEvent | google.maps.IconMouseEvent) => { | ||
| event.stop(); | ||
|
|
||
| if ('placeId' in event && event.placeId) { | ||
| // When the user clicks a POI. | ||
| marker.position = event.latLng; | ||
| placeDetailsRequest.setAttribute( | ||
| 'place', | ||
| `places/${event.placeId}` | ||
| ); | ||
| showInfoWindow(); | ||
| } else { | ||
| // When the user clicks the map (not on a POI). | ||
| marker.position = null; | ||
| placeDetailsRequest.removeAttribute('place'); | ||
| console.log('No place was selected.'); | ||
| } | ||
| } | ||
| ); | ||
| } | ||
| /* [END maps_ui_kit_advanced_place_details_compact_event] */ | ||
| void init(); | ||
| /* [END maps_ui_kit_advanced_place_details_compact] */ | ||
12 changes: 12 additions & 0 deletions
12
samples/ui-kit-advanced-place-details-compact/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "name": "@js-api-samples/ui-kit-advanced-place-details-compact", | ||
| "version": "1.0.0", | ||
| "scripts": { | ||
| "build": "bash ../build-single.sh", | ||
| "test": "tsc && npm run build:vite --workspace=.", | ||
| "start": "tsc && vite build --config ../../vite.config.js --base './' && vite --config ../../vite.config.js", | ||
| "build:vite": "vite build --config ../../vite.config.js --base './'", | ||
| "preview": "vite preview --config ../../vite.config.js" | ||
| }, | ||
| "author": "Google LLC" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * @license | ||
| * Copyright 2026 Google LLC. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /* [START maps_ui_kit_place_details_compact] */ | ||
| /* | ||
| * Optional: Makes the sample page fill the window. | ||
| */ | ||
| html, | ||
| body { | ||
| height: 100%; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .container { | ||
| display: flex; | ||
| height: 100vh; | ||
| width: 100%; | ||
| } | ||
|
|
||
| gmp-map { | ||
| flex-grow: 1; | ||
| } | ||
| /* [END maps_ui_kit_place_details_compact] */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "rootDir": "." | ||
| }, | ||
| "include": ["./*.ts"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Google Maps JavaScript Sample | ||
|
|
||
| ## ui-kit-advanced-place-details | ||
|
|
||
| The ui-kit-advanced-place-details sample demonstrates how to use the UI Kit Place Details element. | ||
|
|
||
| Follow these instructions to set up and run ui-kit-advanced-place-details 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=ui-kit-advanced-place-details/` | ||
|
|
||
| ### 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <!-- | ||
| @license | ||
| Copyright 2026 Google LLC. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
| <!--[START maps_ui_kit_advanced_place_details] --> | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>Place Details with Google Maps</title> | ||
| <meta charset="utf-8" /> | ||
| <link rel="stylesheet" type="text/css" href="style.css" /> | ||
| <script type="module" src="./index.js"></script> | ||
| <script> | ||
| // prettier-ignore | ||
| (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: "GOOGLE_MAPS_API_KEY", | ||
| v: "beta" | ||
| }); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <!--[START maps_ui_kit_advanced_place_details_map] --> | ||
| <div class="container"> | ||
| <!-- map-id is required to use advanced markers. See https://developers.google.com/maps/documentation/javascript/map-ids/mapid-over. --> | ||
| <gmp-map zoom="17" map-id="DEMO_MAP_ID"> | ||
| <gmp-advanced-marker></gmp-advanced-marker> | ||
| </gmp-map> | ||
| <div class="ui-panel"> | ||
| <gmp-advanced-place-details> | ||
| <gmp-place-details-place-request | ||
| place="places/ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request> | ||
|
|
||
|
ejhaselden marked this conversation as resolved.
|
||
| <gmp-place-name></gmp-place-name> | ||
| <gmp-place-address></gmp-place-address> | ||
| <gmp-place-rating></gmp-place-rating> | ||
| <gmp-place-type></gmp-place-type> | ||
| <gmp-place-price></gmp-place-price> | ||
| <gmp-place-accessible-entrance-icon></gmp-place-accessible-entrance-icon> | ||
| <gmp-place-opening-hours></gmp-place-opening-hours> | ||
| <gmp-place-website></gmp-place-website> | ||
| <gmp-place-phone-number></gmp-place-phone-number> | ||
| <gmp-place-summary></gmp-place-summary> | ||
| <gmp-place-type-specific-highlights></gmp-place-type-specific-highlights> | ||
| <gmp-place-review-summary></gmp-place-review-summary> | ||
| <gmp-place-reviews></gmp-place-reviews> | ||
| <gmp-place-feature-list></gmp-place-feature-list> | ||
| </gmp-advanced-place-details> | ||
| </div> | ||
| </div> | ||
| <!--[END maps_ui_kit_advanced_place_details_map] --> | ||
| </body> | ||
| </html> | ||
| <!--[END maps_ui_kit_advanced_place_details] --> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.