The AdvancedPlaceListElement is an HTML element that renders a collection of places in a list given their Place Resource Names.
The Advanced Place List Element offers advanced features, including customizing action buttons, configuring Place attribution, and handling errors.
Basic usage
To use the component, add a <gmp-advanced-place-list>
element to your page and pass a space-separated list of place resource names
via the places attribute.
See a complete code example
TypeScript
async function init() { await google.maps.importLibrary('places'); await customElements.whenDefined('gmp-advanced-place-list'); const listElement = document.querySelector('gmp-advanced-place-list'); if (listElement) { listElement.addEventListener('gmp-error', (e: Event) => { const customEvent = e as CustomEvent<{ errors?: unknown }>; console.error( 'Failed to load places: ', customEvent.detail.errors ?? customEvent ); }); } } void init();
JavaScript
async function init() { await google.maps.importLibrary('places'); await customElements.whenDefined('gmp-advanced-place-list'); const listElement = document.querySelector('gmp-advanced-place-list'); if (listElement) { listElement.addEventListener('gmp-error', (e) => { const customEvent = e; console.error( 'Failed to load places: ', customEvent.detail.errors ?? customEvent ); }); } } void init();
CSS
html, body { height: 100%; margin: 0; padding: 0; font-family: Roboto, Arial, sans-serif; }
HTML
<!doctype html>
<html>
<head>
<title>Advanced Place List</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<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>
<gmp-advanced-place-list
places="places/ChIJLU7jZClu5kcR4PcOOO6p3I0 places/ChIJrRMgU7ZhLxMRxAOFkC7I8Sg places/ChIJbf8C1yFxdDkR3n12P4DkKt0 places/ChIJPTacEpBQwokRKwIlDXelxkA places/ChIJVVVViV-abZERJxqgpA43EDo">
<template slot="details-item">
<gmp-place-name></gmp-place-name>
<gmp-place-address></gmp-place-address>
<gmp-place-media query="coffee"></gmp-place-media>
</template>
</gmp-advanced-place-list>
</body>
</html>Advanced features
Customize action buttons
Add action buttons as children inside the
<template slot="details-item"> element of the Advanced
Place List component. Use <gmp-place-link> for standard
navigational connections, and explicitly specify the action
attribute. You can optionally specify the slot attribute. Valid
predefined actions are open-website,
open-directions, open-map, and call. If
the slot attribute is omitted, it defaults to
action-main.
<gmp-advanced-place-list places="places/ChIJT7FdmYiAhYAROFOvrIxRJDU">
<template slot="details-item">
<gmp-place-name></gmp-place-name>
<gmp-place-link action="open-website" target="_blank"></gmp-place-link>
<gmp-place-link action="open-directions" slot="action-corner"></gmp-place-link>
</template>
</gmp-advanced-place-list>Configure Place attribution
To configure visual attribution, add a
<gmp-place-attribution> element to display overarching Maps
API data attribution configurations, such as the source of a photo or review.
It must be added as a direct sibling of the <template>.
Attributions placed inside the <template> element
will be ignored.
<gmp-advanced-place-list places="places/ChIJT7FdmYiAhYAROFOvrIxRJDU">
<template slot="details-item">
<gmp-place-name></gmp-place-name>
</template>
<gmp-place-attribution light-scheme-color="black" dark-scheme-color="gray"></gmp-place-attribution>
</gmp-advanced-place-list>Handle errors
You can listen for the gmp-error event to gracefully handle
scenarios when one or more requested places fail to load.
const listElement = document.querySelector('gmp-advanced-place-list'); listElement.addEventListener('gmp-error', (e) => { // e.detail.errors contains an array of failure objects with specific failed Resource Names console.error('Failed to load places: ', e.detail.errors); });