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
4 changes: 2 additions & 2 deletions dist/samples/ui-kit-place-search-text-compact/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<head>
<title>Places UI Kit: Place (text) search with Place Details Compact</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="map-container"></div>
Expand Down Expand Up @@ -38,7 +39,6 @@
v: "alpha"
});
</script>
<script type="text/JavaScript" src="app.js"></script>
</body>
</html>
<!--[END maps_ui_kit_place_search_text_compact] -->
157 changes: 157 additions & 0 deletions dist/samples/ui-kit-place-search-text-compact/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/* [START maps_ui_kit_place_search_text_compact] */
const mapContainer = document.getElementById("map-container") as any;
const placeSearch = document.querySelector("gmp-place-search") as any;
const placeSearchQuery = document.querySelector("gmp-place-text-search-request") as any;
const queryInput = document.querySelector(".query-input") as any;
const searchButton = document.querySelector(".search-button") as any;
const detailsContainer = document.getElementById("details-container") as any;
const placeDetails = document.querySelector("gmp-place-details-compact") as any;
const placeRequest = document.querySelector("gmp-place-details-place-request") as any;
const warningMsg = document.querySelector(".warning") as any;
let markers = {};
let previousSearchQuery = '';
let gMap;
let placeDetailsPopup;

let AdvancedMarkerElement;
let LatLngBounds;
let LatLng;

async function init() {
//@ts-ignore
const {Map} = await google.maps.importLibrary("maps");
await google.maps.importLibrary("places");
//@ts-ignore
({AdvancedMarkerElement} = await google.maps.importLibrary("marker"));
//@ts-ignore
({LatLngBounds, LatLng} = await google.maps.importLibrary("core"));

let mapOptions = {
center: {lat: 37.422, lng: -122.085},
zoom: 2,
mapTypeControl: false,
clickableIcons: false,
mapId: '2439f449ff38ce55'
};

gMap = new Map(mapContainer, mapOptions);

placeDetailsPopup = new AdvancedMarkerElement({
map: null,
content: placeDetails,
zIndex: 100
});

findCurrentLocation();

gMap.addListener('click', (e) => {
hidePlaceDetailsPopup();
});

searchButton.addEventListener("click", searchPlaces);
queryInput.addEventListener("keydown", (event) => {
if (event.key == 'Enter') {
event.preventDefault();
searchPlaces();
}
});

placeSearch.addEventListener("gmp-select", ({ place }) => {
if (markers[place.id]) {
markers[place.id].click();
}
});
}

function searchPlaces(){
if (queryInput.value.trim() === previousSearchQuery) {
return;
}
previousSearchQuery = queryInput.value.trim();
warningMsg.style.display = 'none';
placeDetailsPopup.map = null;

for(const markerId in markers){
if (Object.prototype.hasOwnProperty.call(markers, markerId)) {
markers[markerId].map = null;
}
}
markers = {};
if (queryInput.value) {
mapContainer.style.height = '75vh';
placeSearch.style.display = 'block';
placeSearchQuery.textQuery = queryInput.value;
placeSearchQuery.locationBias = gMap.getBounds();
placeSearch.addEventListener('gmp-load', addMarkers, { once: true });
}
}

async function addMarkers(){
const bounds = new LatLngBounds();

if(placeSearch.places.length > 0){
placeSearch.places.forEach((place) => {
let marker = new AdvancedMarkerElement({
map: gMap,
position: place.location
});

marker.metadata = {id: place.id};
markers[place.id] = marker;
bounds.extend(place.location);

marker.addListener('click',(event) => {
placeRequest.place = place;
placeDetails.style.display = 'block';

placeDetailsPopup.position = place.location;
placeDetailsPopup.map = gMap;

gMap.fitBounds(place.viewport, {top: 200, left: 100});

});
gMap.setCenter(bounds.getCenter());
gMap.fitBounds(bounds);
});
} else {
warningMsg.style.display = "block";
}
}

async function findCurrentLocation(){
//@ts-ignore
const { LatLng } = await google.maps.importLibrary("core");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
const pos = new LatLng(position.coords.latitude,position.coords.longitude);
gMap.panTo(pos);
gMap.setZoom(16);
},
() => {
console.log('The Geolocation service failed.');
gMap.setZoom(16);
//@ts-ignore
},
);
} else {
console.log("Your browser doesn't support geolocation");
gMap.setZoom(16);
}

}

function hidePlaceDetailsPopup() {
if (placeDetailsPopup.map) {
placeDetailsPopup.map = null;
placeDetails.style.display = 'none';
}
}

init();
/* [END maps_ui_kit_place_search_text_compact] */

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<head>
<title>Places UI Kit: Place (text) search with Place Details Compact</title>
<meta charset="utf-8">
<script type="module" crossorigin src="./assets/index-DEw-iLjO.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-xPIYwYQR.css">
</head>
<body>
Expand Down Expand Up @@ -38,7 +39,6 @@
v: "alpha"
});
</script>
<script type="text/JavaScript" src="app.js"></script>
</body>
</html>
<!--[END maps_ui_kit_place_search_text_compact] -->
4 changes: 2 additions & 2 deletions dist/samples/ui-kit-place-search-text-compact/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<head>
<title>Places UI Kit: Place (text) search with Place Details Compact</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="map-container"></div>
Expand Down Expand Up @@ -38,7 +39,6 @@
v: "alpha"
});
</script>
<script type="text/JavaScript" src="app.js"></script>
</body>
</html>
<!--[END maps_ui_kit_place_search_text_compact] -->
135 changes: 135 additions & 0 deletions dist/samples/ui-kit-place-search-text-compact/docs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
"use strict";
/*
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/* [START maps_ui_kit_place_search_text_compact] */
const mapContainer = document.getElementById("map-container");
const placeSearch = document.querySelector("gmp-place-search");
const placeSearchQuery = document.querySelector("gmp-place-text-search-request");
const queryInput = document.querySelector(".query-input");
const searchButton = document.querySelector(".search-button");
const detailsContainer = document.getElementById("details-container");
const placeDetails = document.querySelector("gmp-place-details-compact");
const placeRequest = document.querySelector("gmp-place-details-place-request");
const warningMsg = document.querySelector(".warning");
let markers = {};
let previousSearchQuery = '';
let gMap;
let placeDetailsPopup;
let AdvancedMarkerElement;
let LatLngBounds;
let LatLng;
async function init() {
//@ts-ignore
const { Map } = await google.maps.importLibrary("maps");
await google.maps.importLibrary("places");
//@ts-ignore
({ AdvancedMarkerElement } = await google.maps.importLibrary("marker"));
//@ts-ignore
({ LatLngBounds, LatLng } = await google.maps.importLibrary("core"));
let mapOptions = {
center: { lat: 37.422, lng: -122.085 },
zoom: 2,
mapTypeControl: false,
clickableIcons: false,
mapId: '2439f449ff38ce55'
};
gMap = new Map(mapContainer, mapOptions);
placeDetailsPopup = new AdvancedMarkerElement({
map: null,
content: placeDetails,
zIndex: 100
});
findCurrentLocation();
gMap.addListener('click', (e) => {
hidePlaceDetailsPopup();
});
searchButton.addEventListener("click", searchPlaces);
queryInput.addEventListener("keydown", (event) => {
if (event.key == 'Enter') {
event.preventDefault();
searchPlaces();
}
});
placeSearch.addEventListener("gmp-select", ({ place }) => {
if (markers[place.id]) {
markers[place.id].click();
}
});
}
function searchPlaces() {
if (queryInput.value.trim() === previousSearchQuery) {
return;
}
previousSearchQuery = queryInput.value.trim();
warningMsg.style.display = 'none';
placeDetailsPopup.map = null;
for (const markerId in markers) {
if (Object.prototype.hasOwnProperty.call(markers, markerId)) {
markers[markerId].map = null;
}
}
markers = {};
if (queryInput.value) {
mapContainer.style.height = '75vh';
placeSearch.style.display = 'block';
placeSearchQuery.textQuery = queryInput.value;
placeSearchQuery.locationBias = gMap.getBounds();
placeSearch.addEventListener('gmp-load', addMarkers, { once: true });
}
}
async function addMarkers() {
const bounds = new LatLngBounds();
if (placeSearch.places.length > 0) {
placeSearch.places.forEach((place) => {
let marker = new AdvancedMarkerElement({
map: gMap,
position: place.location
});
marker.metadata = { id: place.id };
markers[place.id] = marker;
bounds.extend(place.location);
marker.addListener('click', (event) => {
placeRequest.place = place;
placeDetails.style.display = 'block';
placeDetailsPopup.position = place.location;
placeDetailsPopup.map = gMap;
gMap.fitBounds(place.viewport, { top: 200, left: 100 });
});
gMap.setCenter(bounds.getCenter());
gMap.fitBounds(bounds);
});
}
else {
warningMsg.style.display = "block";
}
}
async function findCurrentLocation() {
//@ts-ignore
const { LatLng } = await google.maps.importLibrary("core");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
const pos = new LatLng(position.coords.latitude, position.coords.longitude);
gMap.panTo(pos);
gMap.setZoom(16);
}, () => {
console.log('The Geolocation service failed.');
gMap.setZoom(16);
//@ts-ignore
});
}
else {
console.log("Your browser doesn't support geolocation");
gMap.setZoom(16);
}
}
function hidePlaceDetailsPopup() {
if (placeDetailsPopup.map) {
placeDetailsPopup.map = null;
placeDetails.style.display = 'none';
}
}
init();
/* [END maps_ui_kit_place_search_text_compact] */
Loading