Get a Maps Demo Key: Try out select Maps JavaScript API and Places UI Kit features at no cost with a Maps Demo Key—no billing information required.

UI Kit Place Details

Click a marker on the map to see its place details in a Place Details Element. Read the documentation.

[フレーム]

TypeScript

// Use querySelector to select elements for interaction.
constmap=document.querySelector('gmp-map')!;
constplaceDetails=document.querySelector('gmp-place-details')!;
constplaceDetailsRequest=document.querySelector(
'gmp-place-details-place-request'
)!;
constmarker=document.querySelector('gmp-advanced-marker')!;
asyncfunctioninit():Promise<void>{
// Request needed libraries.
awaitPromise.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
constupdateMapAndMarker=()=>{
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:google.maps.MapMouseEvent|google.maps.IconMouseEvent)=>{
marker.position=null;
event.stop();
if('placeId'inevent && 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';
}
}
);
}
voidinit();

JavaScript

// Use querySelector to select elements for interaction.
constmap=document.querySelector('gmp-map');
constplaceDetails=document.querySelector('gmp-place-details');
constplaceDetailsRequest=document.querySelector(
'gmp-place-details-place-request'
);
constmarker=document.querySelector('gmp-advanced-marker');
asyncfunctioninit(){
// Request needed libraries.
awaitPromise.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
constupdateMapAndMarker=()=>{
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'inevent && 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';
}
});
}
voidinit();

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>

Clone Sample

Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

gitclonehttps://github.com/googlemaps-samples/js-api-samples.git
cdsamples/ui-kit-place-details
npmi
npmstart

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026年09月01日 UTC.