The Place Details Compact Element (Preview) and Place Details Element (Experimental) are HTML elements that render details for a place:
-
The
PlaceDetailsCompactElement
(Preview) is designed to consume minimal space and display a concise set of information about a place, including name, address, rating, etc. It may also include a single photo. -
The full-size
PlaceDetailsElement
(Experimental) supports a broader range of content elements, including website, phone number, editorial summary, reviews, etc. It may also include multiple photos.
Place Details Compact Element (Preview)
The
PlaceDetailsCompactElement
renders details for a selected place using minimal space. This may be useful in an info window
highlighting a place on a map, in a social media experience like sharing a location in a chat,
as a suggestion for selecting your current location, or within a media article to reference
the place on Google Maps.The PlaceDetailsCompactElement
can display name,
address, rating, type, price, accessibility icon, open status, and a single photo.
To add the element to a map, add a
gmp-place-details-compact
element to the gmp-map
element on the HTML
page, and use the orientation
attribute to set its orientation.
In the following example, gmp-place-details-compact
is nested within a
gmp-map
element, with orientation
set to horizontal
. An
additional attribute, truncation-preferred
, truncates certain content to fit on
one line instead of wrapping.
<gmp-map center="47.75972, -122.25094" zoom="19" map-id="DEMO_MAP_ID"> <gmp-place-details-compact orientation = "horizontal" truncation-preferred slot="control-block-start-inline-center" > <gmp-place-details-place-request place = "ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request> <gmp-place-content-config> <gmp-place-media lightbox-preferred></gmp-place-media> <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> </gmp-place-content-config> </gmp-place-details-compact> <gmp-advanced-marker></gmp-advanced-marker> </gmp-map>
The gmp-place-details-compact
element contains a child element,
gmp-place-details-place-request
, to select the place. This can be a
Place object,
a
place ID,
or a Place's resource name in the format `places/{place_id}:
<gmp-place-details-place-request place = "ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>
You can control the specific place content displayed by the
gmp-place-details-compact
element using a nested
gmp-place-content-config
element to select and configure the place
details. The gmp-place-content-config
element itself contains a number of
child content elements, and each selects a corresponding place detail to display:
PlaceAddressElement
selects the place's address,
PlacePriceElement
selects the place's price level, etc. The order of child elements is irrelevant, as the
selected details are always rendered in a fixed predefined order.
Some of these elements can be further configured using content-specific attributes:
-
The
gmp-place-media
element is used to display a single photo, and includes alightbox-preferred
attribute that opens the photo in a lightbox when clicked. Lightbox is disabled by default. -
The
gmp-place-attribution
element is used to display the source of the photo. Thelight-scheme-color
anddark-scheme-color
attributes are used to set the color of the attribution text in light and dark mode.
PlaceContentConfigElement
reference documentation for more information about all supported content elements.
<gmp-place-content-config> <gmp-place-media lightbox-preferred></gmp-place-media> <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> </gmp-place-content-config>
The gmp-place-details-compact
element also supports a variety of custom CSS
properties to configure the element's colors and fonts. See the reference documentation for
PlaceDetailsCompactElement
for more details.
gmp-place-details-compact { /* Sets the color for text and icons on the surface */ /* Adapts automatically to the user's system light/dark mode preference */ --gmp-mat-color-on-surface: light-dark(black, white); /* Sets the background color of the surface */ /* Adapts automatically to the user's system light/dark mode preference */ --gmp-mat-color-surface: light-dark(white, black); /* Defines the primary font stack used within the component */ --gmp-mat-font-family: Google Sans Text, sans-serif; /* Defines the style for medium body text (e.g., address, descriptions) */ --gmp-mat-font-body-medium: normal 400 0.875em/1.25em var(--gmp-mat-font-family, 'Google Sans Text'); width: 360px; margin-top: 100px; overflow-y: hidden; }

See the complete code example
JavaScript
// Use querySelector to select elements for interaction. const map = document.querySelector('gmp-map'); //@ts-ignore const marker = document.querySelector('gmp-advanced-marker'); async function initMap() { // Request needed libraries. const { Map } = await google.maps.importLibrary("maps"); const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); await google.maps.importLibrary("places"); // Hide the map type control. map.innerMap.setOptions({ mapTypeControl: false }); // Set marker collision behavior. marker.collisionBehavior = google.maps.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL; // Add marker to place location. marker.position = { lat: 47.75972, lng: -122.25094 }; } initMap();
CSS
/* * Optional: Makes the sample page fill the window. */ body { display: flex; width: 100%; height: 100%; } gmp-map { height: 600px; pointer-events: none; } gmp-place-details-compact { /* Sets the color for text and icons on the surface */ /* Adapts automatically to the user's system light/dark mode preference */ --gmp-mat-color-on-surface: light-dark(black, white); /* Sets the background color of the surface */ /* Adapts automatically to the user's system light/dark mode preference */ --gmp-mat-color-surface: light-dark(white, black); /* Defines the primary font stack used within the component */ --gmp-mat-font-family: Google Sans Text, sans-serif; /* Defines the style for medium body text (e.g., address, descriptions) */ --gmp-mat-font-body-medium: normal 400 0.875em/1.25em var(--gmp-mat-font-family, 'Google Sans Text'); width: 360px; margin-top: 100px; overflow-y: hidden; }
HTML
<!DOCTYPE html> <html> <head> <title>Click on the map to view place details</title> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> <script type="module" src="./index.js"></script> </head> <body> <gmp-map center="47.75972, -122.25094" zoom="19" map-id="DEMO_MAP_ID"> <gmp-place-details-compact orientation = "horizontal" slot="control-block-start-inline-center"> <gmp-place-details-place-request place = "ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request> <gmp-place-content-config> <gmp-place-media lightbox-preferred></gmp-place-media> <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> </gmp-place-content-config> </gmp-place-details-compact> <gmp-advanced-marker></gmp-advanced-marker> </gmp-map> <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: "beta"});</script> </body> </html>
Place Details Element (Experimental)
The full-size
PlaceDetailsElement
supports a broader range of content elements, including full opening hours, website, phone
number, editorial summary, type-specific highlights, reviews, plus code, and feature lists.
-
The
configureFromPlace
method renders the Place Details element based on a place ID or aPlace
object. -
The
configureFromLocation
method renders the Place Details element based on latitude and longitude coordinates.
The example in this section renders the Place Details element when the user clicks the map. To
add Place Details to a map, add a gmp-place-details
element to the HTML page. Set
its size and position using the size
and slot
attributes,
respectively. In the following example, it's nested within a gmp-map
element with
size
set to x-large
and slot
set to
control-inline-start-block-start
.
<gmp-map center="47.759737, -122.250632" zoom="16" map-id="DEMO_MAP_ID"> <div class="widget-container" slot="control-inline-start-block-start"> <gmp-place-details size="x-large"></gmp-place-details> </div> <gmp-advanced-marker></gmp-advanced-marker> </gmp-map>
A querySelector
is used to select each page element for interaction:
const map = document.querySelector('gmp-map'); const placeDetails = document.querySelector('gmp-place-details'); const marker = document.querySelector('gmp-advanced-marker');
The event handler in the following snippet renders the Place Details element based on the location of the user's map click:
// Add an event listener to handle map clicks. map.innerMap.addListener('click', async (event) => { marker.position = null; event.stop(); if (event.placeId) { // Fire when the user clicks a POI. await placeDetails.configureFromPlace({ id: event.placeId }); } else { // Fire when the user clicks the map (not on a POI). await placeDetails.configureFromLocation(event.latLng); } // Get the offset center. let adjustedCenter = offsetLatLngRight(placeDetails.place.location, -0.005); // Show the marker at the selected place. marker.position = placeDetails.place.location; marker.style.display = 'block'; map.innerMap.panTo(adjustedCenter); }); }
See the complete code example
JavaScript
// Use querySelector to select elements for interaction. const map = document.querySelector('gmp-map'); const placeDetails = document.querySelector('gmp-place-details'); const marker = document.querySelector('gmp-advanced-marker'); let center = { lat: 47.759737, lng: -122.250632 }; async function initMap() { // Request needed libraries. const { Map } = await google.maps.importLibrary("maps"); const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker"); const { Place } = await google.maps.importLibrary("places"); // Hide the map type control. map.innerMap.setOptions({ mapTypeControl: false }); // Set the default selection. const place = new Place({ id: "ChIJC8HakaIRkFQRiOgkgdHmqkk", requestedLanguage: "en", // optional }); await placeDetails.configureFromPlace(place); let adjustedCenter = offsetLatLngRight(placeDetails.place.location, -0.005); map.innerMap.panTo(adjustedCenter); map.innerMap.setZoom(16); marker.position = placeDetails.place.location; marker.style.display = 'block'; marker.collisionBehavior = google.maps.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL; // Add an event listener to handle map clicks. map.innerMap.addListener('click', async (event) => { marker.position = null; event.stop(); if (event.placeId) { // Fire when the user clicks a POI. await placeDetails.configureFromPlace({ id: event.placeId }); } else { // Fire when the user clicks the map (not on a POI). await placeDetails.configureFromLocation(event.latLng); } // Get the offset center. let adjustedCenter = offsetLatLngRight(placeDetails.place.location, -0.005); // Show the marker at the selected place. marker.position = placeDetails.place.location; marker.style.display = 'block'; map.innerMap.panTo(adjustedCenter); }); } // Helper function to offset the map center. function offsetLatLngRight(latLng, longitudeOffset) { const newLng = latLng.lng() + longitudeOffset; return new google.maps.LatLng(latLng.lat(), newLng); } initMap();
CSS
/* * Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; font-family: Arial, Helvetica, sans-serif; display: block; } h1 { font-size: 16px; text-align: center; } gmp-map { height: 400px; } gmp-place-details { background-color: #fff; border-radius: 8px; margin: 20px; width: 400px; padding: 12px; margin-top: 10px; overflow-y: auto; } gmp-advanced-marker { display: none; } .widget-container { height: 400px; width: 457px; overflow-y: auto; overflow-x: hidden; }
HTML
<!DOCTYPE html> <html> <head> <title>Click on the map to view place details</title> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> <script type="module" src="./index.js"></script> </head> <body> <gmp-map center="47.759737, -122.250632" zoom="16" map-id="DEMO_MAP_ID"> <div class="widget-container" slot="control-inline-start-block-start"> <gmp-place-details size="x-large"></gmp-place-details> </div> <gmp-advanced-marker></gmp-advanced-marker> </gmp-map> <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: "alpha"});</script> </body> </html>