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
1 change: 0 additions & 1 deletion samples/ui-kit-place-search/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<script type="module" src="./index.js"></script>
</head>
<body>
<h1>Place List Nearby Search with Google Maps</h1>
<!--[START maps_ui_kit_place_search_map] -->
<gmp-map center="-37.813,144.963" zoom="10" map-id="DEMO_MAP_ID">
<div class="overlay" slot="control-inline-start-block-start">
Expand Down
21 changes: 11 additions & 10 deletions samples/ui-kit-place-search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ const placeDetails = document.querySelector("gmp-place-details") as any;
let marker = document.querySelector('gmp-advanced-marker') as any;
/* [END maps_ui_kit_place_search_query_selectors] */
let markers = {};
let infowindow;
let infoWindow;
let mapCenter;

async function initMap(): Promise<void> {
await google.maps.importLibrary("places");
const { InfoWindow } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
const { spherical } = await google.maps.importLibrary("geometry") as google.maps.GeometryLibrary;

infowindow = new google.maps.InfoWindow;
infoWindow = new google.maps.InfoWindow;

function getContainingCircle(bounds) {
const diameter = spherical.computeDistanceBetween(
bounds.getNorthEast(),
bounds.getSouthWest()
);
return { center: bounds.getCenter(), radius: diameter / 2 };
const calculatedRadius = diameter / 2;
const cappedRadius = Math.min(calculatedRadius, 50000); // Cap the radius to avoid an error.
return { center: bounds.getCenter(), radius: cappedRadius };
}

findCurrentLocation();
Expand All @@ -41,7 +43,6 @@ async function initMap(): Promise<void> {
typeSelect.addEventListener("change", (event) => {
// First remove all existing markers.
for(marker in markers){
console.log(marker);
markers[marker].map = null;
}
markers = {};
Expand All @@ -53,7 +54,7 @@ async function initMap(): Promise<void> {
),
includedPrimaryTypes: [typeSelect.value],
}).then(addMarkers);

// Handle user selection in Place Details.
placeList.addEventListener("gmp-placeselect", ({ place }) => {
markers[place.id].click();
});
Expand All @@ -79,20 +80,20 @@ async function addMarkers(){
bounds.extend(place.location);

marker.addListener('gmp-click',(event) => {
if(infowindow.isOpen){
infowindow.close();
if(infoWindow.isOpen){
infoWindow.close();
}
placeDetails.configureFromPlace(place);
placeDetails.style.width = "350px";
infowindow.setOptions({
infoWindow.setOptions({
content: placeDetails
});
infowindow.open({
infoWindow.open({
anchor: marker,
map: map.innerMap
});
placeDetails.addEventListener('gmp-load',() => {
map.innerMap.fitBounds(place.viewport, {top: placeDetails.offsetHeight || 206, left: 200});
map.innerMap.fitBounds(place.viewport, { top: 400, left: 200 });
});

});
Expand Down
5 changes: 4 additions & 1 deletion samples/ui-kit-place-search/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ html,
gmp-map {
box-sizing: border-box;
padding: 0 20px 20px;
height: 600px;
}

.overlay {
position: relative;
top: 40px;
margin: 20px;
width: 400px;
}
Expand Down Expand Up @@ -55,7 +58,7 @@ html,
}

.list-container {
height: 600px;
height: 400px;
overflow: auto;
border-radius: 10px;
}
Expand Down