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
8 changes: 4 additions & 4 deletions samples/ui-kit-place-details/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
</head>
<body>
<!--[START maps_ui_kit_place_details_map] -->
<gmp-map center="-37.813,144.963" zoom="2" map-id="DEMO_MAP_ID">
<gmp-place-details
size="x-large"
slot="control-inline-start-block-start"></gmp-place-details>
<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>
<!--[END maps_ui_kit_place_details_map] -->
Expand Down
58 changes: 28 additions & 30 deletions samples/ui-kit-place-details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,58 @@ const placeDetails = document.querySelector('gmp-place-details') as any;
const marker = document.querySelector('gmp-advanced-marker') as any;
/* [END maps_ui_kit_place_details_query_selector] */

async function initMap(): Promise<void> {
// Request needed libraries.
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary;
let center = { lat: 47.759737, lng: -122.250632 };

// Calls the geolocation helper function to center the map on the current
// device location.
findCurrentLocation();
async function initMap(): Promise<void> {
// Request needed libraries.
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary;

// 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';

/* [START maps_ui_kit_place_details_event] */
// Add an event listener to handle map clicks.
map.innerMap.addListener('click', async (event) => {
marker.position = null;
event.stop();
placeDetails.style.visibility = 'visible';
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);
});
}
/* [END maps_ui_kit_place_details_event] */

// Helper function for geolocation.
async function findCurrentLocation() {
const { LatLng } = await google.maps.importLibrary('core') as google.maps.CoreLibrary;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
const pos =
new LatLng(position.coords.latitude, position.coords.longitude);
map.innerMap.panTo(pos);
map.innerMap.setZoom(16);
},
() => {
console.log('The Geolocation service failed.');
map.innerMap.setZoom(16);
},
);
} else {
console.log('Your browser doesn\'t support geolocation');
map.innerMap.setZoom(16);
}
// Helper function to offset the map center.
function offsetLatLngRight(latLng, longitudeOffset) {
const newLng = latLng.lng() + longitudeOffset;
return new google.maps.LatLng(latLng.lat(), newLng);
}
/* [END maps_ui_kit_place_details_event] */

declare global {
interface Window {
Expand Down
14 changes: 12 additions & 2 deletions samples/ui-kit-place-details/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ body {
height: 100%;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
display: block;
}

h1 {
Expand All @@ -20,18 +21,27 @@ h1 {
}

gmp-map {
height: 800px;
height: 400px;
}

gmp-place-details {
visibility: hidden;
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;
}
/* [END maps_ui_kit_place_details] */