Place Details 要素と Place Details Compact 要素は、場所の詳細をレンダリングする HTML 要素です。
-
PlaceDetailsElementは、すべての可視化可能な Place データをサポートしており、複数の写真を含めることができます。 -
PlaceDetailsCompactElementは、最小限のスペースで、場所に関する簡潔な情報(名前、住所、評価など)を表示するように設計されています。1 枚の写真を含めることもできます。
カスタマイズ ツールを使用すると、さまざまなプロパティのセットが Place Details 要素の外観にどのように影響するかを視覚化し、HTML/CSS、Kotlin/XML、Swift のコードにアクセスできます。
エージェント アプリのトークン
エージェント型データ可視化トークンを使用すると、エージェント型アプリは、Maps Experience Agent Tools(旧称 Maps Grounding Lite)のレスポンスに含まれる場所の Places UI キット 要素を追加料金なしで表示できます。詳細については、エージェント データ可視化トークンをご覧ください。
Place Details の要素
地図上のマーカーをクリックすると、Place Details 要素に場所の詳細が表示されます。
PlaceDetailsElement は、完全な営業時間、混雑する時間帯、ウェブサイト、電話番号、AI による要約(編集要約へのフォールバックあり)、タイプ固有のハイライト、クチコミ、AI によるクチコミの要約、Plus Code、機能リストなど、幅広いコンテンツ要素をサポートしています。
地図に Place Details を表示するには、HTML ページの gmp-map 要素に gmp-place-details 要素を追加します。子要素 gmp-place-details-place-request を含めて、場所を選択します。Place オブジェクト、プレイス ID、または Place のリソース名を指定できます。
<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>
<gmp-place-details-place-request place="ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>
<gmp-place-all-content></gmp-place-all-content>
</gmp-place-details>
</div>
<gmp-advanced-marker></gmp-advanced-marker>
</gmp-map>コンテンツを構成する
gmp-place-details 要素によって表示される特定の場所のコンテンツを制御するには、次の例に示すように、子要素をネストして Place Details を選択して構成します。
<gmp-place-details>
<gmp-place-details-place-request
place="ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>
<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-popular-times></gmp-place-popular-times>
<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-place-details>
各子コンテンツ要素は、表示する対応する Place Details を選択します。gmp-place-address は場所の住所を選択し、gmp-place-price は場所の価格レベルなどを選択します。要素 gmp-place-summary と gmp-place-review-summary は、それぞれ場所とそのクチコミの AI による概要を提供します。選択した詳細は常に事前定義された固定の順序でレンダリングされるため、子要素の順序は関係ありません。指定したコンテンツ要素のみが表示されるため、場所の名前を表示するには gmp-place-name を指定します。
これらの要素の一部は、コンテンツ固有の属性を使用してさらに構成できます。
-
gmp-place-media要素は 1 枚の写真を表示するために使用され、クリックするとライトボックスで写真を開くlightbox-preferred属性が含まれています。ライトボックスはデフォルトで無効になっています。 -
gmp-place-attribution要素は、写真のソースを表示するために使用されます。light-scheme-color属性とdark-scheme-color属性は、ライトモードとダークモードでの帰属表示テキストの色を設定するために使用されます。
サポートされているすべてのコンテンツ要素の詳細については、Place Widget のコンテンツのカスタマイズのリファレンス ドキュメントをご覧ください。
簡略化のために、gmp-place-all-content を使用して Place Details 要素で使用可能なすべての詳細を表示したり、gmp-place-standard-content を使用して標準構成を表示したりすることもできます。どちらの要素にも場所の名前が含まれます。
混雑する時間帯
gmp-place-popular-times
- 曜日ごとの 1 時間あたりの混雑状況を示すインタラクティブなヒストグラム。デフォルトでは、その場所の現在の現地時間が表示されます。
- 現在の混雑状況(利用可能な場合は「ライブ: 通常より混雑しています」などのライブの混雑状況、または過去の一般的な混雑状況)と、現在の時間帯の一般的な待ち時間。
- 選択した日のピーク時の待ち時間(利用可能な場合)。
gmp-place-details 要素で gmp-place-all-content または gmp-place-standard-content を使用すると、混雑する時間帯が自動的に含まれます。また、gmp-place-details の直接の子として gmp-place-popular-times を含めることもできます。gmp-place-popular-times 要素は、完全な PlaceDetailsElement と AdvancedPlaceDetailsElement でのみサポートされています(PlaceDetailsCompactElement、AdvancedPlaceDetailsCompactElement、非推奨の gmp-place-content-config 要素ではサポートされていません)。
すべての場所に混雑する時間帯のデータがあるわけではありません。場所の混雑する時間帯のデータが利用できない場合、このセクションはエラーなしで省略されます。混雑する時間帯のデータがレンダリングされたかどうかを確認するには、親要素が gmp-load イベントを発生させた後に、PlacePopularTimesElement の読み取り専用の rendered プロパティを使用します。
const detailsElement = document.querySelector('gmp-place-details'); const popularTimesElement = detailsElement.querySelector('gmp-place-popular-times'); detailsElement.addEventListener('gmp-load', () => { console.log('Popular times rendered:', popularTimesElement.rendered); });
--gmp-popular-times-bar-color、--gmp-popular-times-bar-current-hour-color、--gmp-popular-times-bar-current-hour-live-color の CSS プロパティを使用して、人気の時間帯のヒストグラム バーとライブの混雑状況インジケーターの色をカスタマイズできます。詳しくは、Places UI キットのカスタム スタイルをご覧ください。
外観を構成する
gmp-place-details 要素の推奨幅範囲は 250 ~ 400 ピクセルです。幅が 250 ピクセル未満の場合、正しく表示されないことがあります。アプリケーションに合わせて高さを設定します。Place Details 要素は、必要に応じて割り当てられたスペース内でスクロールするように設計されています。
gmp-place-details 要素は、要素の色とフォントを構成するためのさまざまなカスタム CSS プロパティもサポートしています。詳しくは、Places UI キットのカスタム スタイルをご覧ください。
コードサンプルの全文を見る
JavaScript
// Use querySelector to select elements for interaction. const map = document.querySelector('gmp-map'); const placeDetails = document.querySelector('gmp-place-details'); const placeDetailsRequest = document.querySelector( 'gmp-place-details-place-request' ); const marker = document.querySelector('gmp-advanced-marker'); async function init() { // Request needed libraries. await Promise.all([ google.maps.importLibrary('maps'), google.maps.importLibrary('marker'), google.maps.importLibrary('places'), ]); // Hide the map type control. map.innerMap.setOptions({ mapTypeControl: false }); // Function to update map and marker based on place details const updateMapAndMarker = () => { if (placeDetails.place?.location) { map.innerMap.panTo(placeDetails.place.location); map.innerMap.setZoom(16); // Set zoom after panning if needed marker.position = placeDetails.place.location; marker.collisionBehavior = 'REQUIRED_AND_HIDES_OPTIONAL'; marker.style.display = 'block'; } }; // Set up map once widget is loaded. placeDetails.addEventListener('gmp-load', () => { updateMapAndMarker(); }); // Add an event listener to handle clicks. map.innerMap.addListener('click', (event) => { marker.position = null; event.stop(); if ('placeId' in event && event.placeId) { // Fire when the user clicks a POI. placeDetailsRequest.place = event.placeId; updateMapAndMarker(); } else { // Fire when the user clicks the map (not on a POI). console.log('No place was selected.'); marker.style.display = 'none'; } }); } void init();
CSS
/* * 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; } .ui-panel { width: 400px; margin-left: 20px; margin-top: 10px; } gmp-place-details { width: 100%; margin: 0; border: none; }
HTML
<!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"
});
</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 class="ui-panel">
<gmp-place-details>
<gmp-place-details-place-request
place="ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>
<gmp-place-content-config>
<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-place-content-config>
</gmp-place-details>
</div>
</div>
</body>
</html>サンプルを試す
Place Details Compact 要素
地図上のマーカーをクリックすると、Place Details Compact Element に場所の詳細が表示されます。
PlaceDetailsCompactElement は、選択した場所の詳細を最小限のスペースで表示します。これは、地図上の場所をハイライト表示する情報ウィンドウ、チャットでの位置情報の共有などのソーシャル メディア エクスペリエンス、現在地を選択するための候補、メディア記事内で Google マップ上の場所を参照する場合などに役立ちます。PlaceDetailsCompactElement には、表示名、住所、評価、タイプ、価格、ユーザー補助アイコン、営業状況、1 枚の写真を表示できます。orientation 属性で選択したとおりに、水平方向または垂直方向に表示できます。
次のスニペットでは、gmp-place-details-compact が orientation を horizontal に設定して構成されています。追加の属性 truncation-preferred は、特定のコンテンツを折り返すのではなく、1 行に収まるように切り詰めます。gmp-place-details-compact 要素には、場所を選択するための子要素 gmp-place-details-place-request が含まれています。Place オブジェクト、プレイス ID、または Place のリソース名を指定できます。
<gmp-place-details-compact orientation="horizontal" truncation-preferred>
<gmp-place-details-place-request place="ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>
<gmp-place-all-content></gmp-place-all-content>
</gmp-place-details-compact>コンテンツを構成する
gmp-place-details-compact 要素によって表示される特定の場所のコンテンツを制御するには、次のスニペットに示すように、子要素をネストして Place Details を選択して構成します。
<gmp-place-details-compact orientation="horizontal" truncation-preferred> <gmp-place-details-place-request place="ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request> <gmp-place-media lightbox-preferred></gmp-place-media> <gmp-place-name></gmp-place-name> <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-details-compact>
各子コンテンツ要素は、表示する対応する Place Details を選択します。選択した詳細は常に事前に定義された固定の順序でレンダリングされるため、子要素の順序は関係ありません。指定したコンテンツ要素のみが表示されるため、場所の名前を表示するには gmp-place-name を指定します。これらの要素の一部は、コンテンツ固有の属性を使用してさらに構成できます。
サポートされているすべてのコンテンツ要素の詳細については、Place Widget のコンテンツのカスタマイズのリファレンス ドキュメントをご覧ください。
簡略化のために、gmp-place-all-content を使用して Place Details Compact 要素で使用可能なすべての詳細を表示したり、gmp-place-standard-content を使用して標準構成を表示したりすることもできます。どちらの要素にも場所の名前が含まれます。
外観を構成する
縦向きの gmp-place-details-compact 要素の推奨幅範囲は 180 ~ 300 ピクセルです。幅が 160 ピクセル未満の場合、正しく表示されないことがあります。高さを固定しないでください。
横向きの gmp-place-details-compact 要素の推奨幅範囲は 180px ~ 500px です。幅が 160 ピクセル未満の場合、正しく表示されないことがあります。幅が 350 ピクセル未満の場合、サムネイル画像は表示されません。高さを固定しないでください。
gmp-place-details-compact 要素は、要素の色とフォントを構成するためのさまざまなカスタム CSS プロパティもサポートしています。詳しくは、Places UI キットのカスタム スタイルをご覧ください。
Place Details Compact 要素を情報ウィンドウに追加する場合は、gmp-place-details-compact 要素にカスタム スタイルを直接適用する必要があります。これは、情報ウィンドウが地図のシャドウ DOM の一部であり、外部 CSS スタイルが適用されないためです。
<gmp-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="ChIJC8HakaIRkFQRiOgkgdHmqkk"></gmp-place-details-place-request>コードサンプルの全文を見る
この例では、InfoWindow と AdvancedMarkerElement を使用して、プログラムで PlaceDetailsCompactElement を地図に追加する方法を示します。
JavaScript
// Use querySelector to select elements for interaction. const map = document.querySelector('gmp-map'); const placeDetails = document.querySelector('gmp-place-details-compact'); const placeDetailsRequest = document.querySelector( 'gmp-place-details-place-request' ); const marker = document.querySelector('gmp-advanced-marker'); async function init() { // 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(); } }); // Add an event listener to handle clicks. map.innerMap.addListener('click', (event) => { event.stop(); if ('placeId' in event) { // When the user clicks a POI. marker.position = event.latLng; placeDetailsRequest.place = event.placeId; showInfoWindow(); } else { // When the user clicks the map (not on a POI). marker.position = null; placeDetailsRequest.place = null; console.log('No place was selected.'); } }); } void init();
CSS
/* * 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; }
HTML
<!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"
});
</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-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.
-->
<gmp-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="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>
</body>
</html>