Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 35 additions & 59 deletions samples/ui-kit-place-details/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,46 @@
<!doctype html>
<html>
<head>
<title>Click on the map to view place details</title>
<title>Place Details with Google Maps</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<script type="module" src="./index.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="module" src="./index.js" defer></script>
<!-- prettier-ignore -->
<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: "weekly"});
</script>
</head>
<body>
<!--[START maps_ui_kit_place_details_map] -->
<gmp-map center="47.759737, -122.250632" zoom="16" map-id="DEMO_MAP_ID">
<gmp-advanced-marker></gmp-advanced-marker>
</gmp-map>
<!--[END maps_ui_kit_place_details_map] -->
<!--[START maps_ui_kit_place_details_container] -->
<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 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>
<!--[END maps_ui_kit_place_details_container] -->
<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: 'weekly' });
</script>
<!--[END maps_ui_kit_place_details_map] -->
</body>
</html>
<!--[END maps_ui_kit_place_details] -->
28 changes: 10 additions & 18 deletions samples/ui-kit-place-details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,31 @@
/* [START maps_ui_kit_place_details] */
// Use querySelector to select elements for interaction.
/* [START maps_ui_kit_place_details_query_selector] */
const map = document.querySelector('gmp-map') as any;
const map = document.querySelector('gmp-map') as google.maps.MapElement;
const placeDetails = document.querySelector('gmp-place-details') as any;
const placeDetailsRequest = document.querySelector(
'gmp-place-details-place-request'
) as any;
const marker = document.querySelector('gmp-advanced-marker') as any;
const marker = document.querySelector(
'gmp-advanced-marker'
) as google.maps.marker.AdvancedMarkerElement;
/* [END maps_ui_kit_place_details_query_selector] */

let center = { lat: 47.759737, lng: -122.250632 };

async function initMap(): Promise<void> {
// Request needed libraries.
(await google.maps.importLibrary('maps')) as google.maps.MapsLibrary;
(await google.maps.importLibrary('marker')) as google.maps.MarkerLibrary;
(await google.maps.importLibrary('places')) as google.maps.PlacesLibrary;
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 && placeDetails.place.location) {
let adjustedCenter = offsetLatLngRight(
placeDetails.place.location,
-0.005
);
map.innerMap.panTo(adjustedCenter);
map.innerMap.panTo(placeDetails.place.location);
map.innerMap.setZoom(16); // Set zoom after panning if needed
marker.position = placeDetails.place.location;
marker.collisionBehavior =
Expand Down Expand Up @@ -64,11 +62,5 @@ async function initMap(): Promise<void> {
}
/* [END maps_ui_kit_place_details_event] */

// Helper function to offset marker placement for better visual appearance.
function offsetLatLngRight(latLng, longitudeOffset) {
const newLng = latLng.lng() + longitudeOffset;
return new google.maps.LatLng(latLng.lat(), newLng);
}

initMap();
/* [END maps_ui_kit_place_details] */
36 changes: 15 additions & 21 deletions samples/ui-kit-place-details/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,30 @@
*/
html,
body {
display: flex; /* Use flexbox for layout */
justify-content: center; /* Center the content horizontally */
align-items: flex-start; /* Align items to the top */
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}

h1 {
font-size: 16px;
text-align: center;
.container {
display: flex;
height: 100vh;
width: 100%;
}

gmp-map {
height: 500px;
flex-grow: 1;
}

gmp-place-details {
border-radius: 0px;
margin: 20px;
.ui-panel {
width: 400px;
height: 500px;
margin-top: 0px;
margin-left: 20px;
margin-top: 10px;
}

gmp-advanced-marker {
display: none;
}

.widget-container {
min-width: 400px;
overflow-y: none;
overflow-x: none;
gmp-place-details {
width: 100%;
margin: 0;
border: none;
}
/* [END maps_ui_kit_place_details] */
Loading