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: 1 addition & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h1>Maps JSAPI Samples</h1>
<li><a href='/samples/deckgl-polygon/dist'>deckgl-polygon</a></li>
<li><a href='/samples/map-drawing-terradraw/dist'>map-drawing-terradraw</a></li>
<li><a href='/samples/map-simple/dist'>map-simple</a></li>
<li><a href='/samples/place-autocomplete-basic-map/dist'>place-autocomplete-basic-map</a></li>
<li><a href='/samples/place-autocomplete-data-session/dist'>place-autocomplete-data-session</a></li>
<li><a href='/samples/place-autocomplete-element/dist'>place-autocomplete-element</a></li>
<li><a href='/samples/place-autocomplete-map/dist'>place-autocomplete-map</a></li>
Expand Down
13 changes: 13 additions & 0 deletions dist/samples/place-autocomplete-basic-map/app/.eslintsrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-this-alias": 1,
"@typescript-eslint/no-empty-function": 1,
"@typescript-eslint/explicit-module-boundary-types": 1,
"@typescript-eslint/no-unused-vars": 1
}
}
33 changes: 33 additions & 0 deletions dist/samples/place-autocomplete-basic-map/app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Google Maps JavaScript Sample

This sample is generated from @googlemaps/js-samples located at
https://github.com/googlemaps-samples/js-api-samples.

## Setup

### Before starting run:

`npm i`

### Run an example on a local web server

First `cd` to the folder for the sample to run, then:

`npm start`

### Build an individual example

From `samples/`:

`npm run build --workspace=sample-name/`

### Build all of the examples.

From `samples/`:

`npm run build-all`

## Feedback

For feedback related to this sample, please open a new issue on
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
32 changes: 32 additions & 0 deletions dist/samples/place-autocomplete-basic-map/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_place_autocomplete_basic_map] -->
<html>
<head>
<title>Place Autocomplete map</title>

<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="map-container">
<gmp-basic-place-autocomplete></gmp-basic-place-autocomplete>
<gmp-place-details-compact orientation="horizontal">
<gmp-place-details-place-request></gmp-place-details-place-request>
<gmp-place-all-content></gmp-place-all-content>
</gmp-place-details-compact>
<gmp-map zoom="14" map-id="DEMO_MAP_ID">
<gmp-advanced-marker></gmp-advanced-marker>
</gmp-map>
</div>

<!-- 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>
</body>
</html>
<!-- [END maps_place_autocomplete_basic_map] -->
64 changes: 64 additions & 0 deletions dist/samples/place-autocomplete-basic-map/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/


// [START maps_place_autocomplete_basic_map]
const mapContainer = document.getElementById("map-container") as any;
const autocompleteElement = document.querySelector('gmp-basic-place-autocomplete') as any;
const detailsElement = document.querySelector('gmp-place-details-compact') as any;
const mapElement = document.querySelector('gmp-map') as any;
const advancedMarkerElement = document.querySelector('gmp-advanced-marker') as any;

let center = { lat: 40.749933, lng: -73.98633 }; // New York City

async function initMap(): Promise<void>{
//@ts-ignore
const {BasicPlaceAutocompleteElement, PlaceDetailsElement} = await google.maps.importLibrary('places');
//@ts-ignore
const {AdvancedMarkerElement} = await google.maps.importLibrary('marker');
//@ts-ignore
const {LatLngBounds} = await google.maps.importLibrary('core');

// Set the initial map location and autocomplete location bias
mapElement.center = center
autocompleteElement.locationBias = center;

// Get the underlying google.maps.Map object to add listeners
const map = mapElement.innerMap;

// Add the listener tochange locationBias to locationRestriction when the map moves
map.addListener('bounds_changed', () => {
autocompleteElement.locationBias = null;
autocompleteElement.locationRestriction = map.getBounds();
console.log("bias changed to restriction")
});

// [START maps_place_autocomplete_basic_map_listener]
// Add the listener to update the Place Request element when the user selects a prediction
autocompleteElement.addEventListener('gmp-select', async (event) => {
const placeDetailsRequest = document.querySelector('gmp-place-details-place-request') as any;
placeDetailsRequest.place = event.place.id;
});
// [END maps_place_autocomplete_basic_map_listener]

// Add the listener to update the marker when the Details element loads
detailsElement.addEventListener('gmp-load', async () => {
const location = detailsElement.place.location;
detailsElement.style.display = "block"
advancedMarkerElement.position = location;
advancedMarkerElement.content = detailsElement;
if (detailsElement.place.viewport) {
map.fitBounds(detailsElement.place.viewport);
} else {
map.setCenter(location);
map.setZoom(17);
}
});
}

initMap();
// [END maps_place_autocomplete_basic_map]

14 changes: 14 additions & 0 deletions dist/samples/place-autocomplete-basic-map/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@js-api-samples/place-autocomplete-basic-map",
"version": "1.0.0",
"scripts": {
"build": "tsc && bash ../jsfiddle.sh place-autocomplete-basic-map && bash ../app.sh place-autocomplete-basic-map && bash ../docs.sh place-autocomplete-basic-map && npm run build:vite --workspace=. && bash ../dist.sh place-autocomplete-basic-map",
"test": "tsc && npm run build:vite --workspace=.",
"start": "tsc && vite build --base './' && vite",
"build:vite": "vite build --base './'",
"preview": "vite preview"
},
"dependencies": {

}
}
60 changes: 60 additions & 0 deletions dist/samples/place-autocomplete-basic-map/app/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/* [START maps_place_autocomplete_basic_map] */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}

#map-container {
display: flex;
flex-direction: row;
height: 100%;
}

#gmp-map {
height: 100%;
}

gmp-basic-place-autocomplete {
position: absolute;
height: 50px;
top: 10px;
left: 10px;
z-index: 1;
box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.2);
color-scheme: light;
border-radius: 10px;
}

gmp-place-details-compact {
width: 360px;
max-height: 300px;
border: none;
padding: 0;
margin: 0;
position: absolute;
transform: translate(calc(-180px), calc(-215px));
box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.2);
color-scheme: light;
}

/* This creates the pointer attached to the bottom of the element. */
gmp-place-details-compact::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 0;
border-left: 16px solid transparent;
border-right: 16px solid transparent;
border-top: 20px solid var(--gmp-mat-color-surface, light-dark(white, black));
}
/* [END maps_place_autocomplete_basic_map] */
17 changes: 17 additions & 0 deletions dist/samples/place-autocomplete-basic-map/app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"strict": true,
"noImplicitAny": false,
"lib": [
"es2015",
"esnext",
"es6",
"dom",
"dom.iterable"
],
"moduleResolution": "Node",
"jsx": "preserve"
}
}

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

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

32 changes: 32 additions & 0 deletions dist/samples/place-autocomplete-basic-map/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_place_autocomplete_basic_map] -->
<html>
<head>
<title>Place Autocomplete map</title>

<script type="module" crossorigin src="./assets/index-D9sGUCsY.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-BmNok-li.css">
</head>
<body>
<div id="map-container">
<gmp-basic-place-autocomplete></gmp-basic-place-autocomplete>
<gmp-place-details-compact orientation="horizontal">
<gmp-place-details-place-request></gmp-place-details-place-request>
<gmp-place-all-content></gmp-place-all-content>
</gmp-place-details-compact>
<gmp-map zoom="14" map-id="DEMO_MAP_ID">
<gmp-advanced-marker></gmp-advanced-marker>
</gmp-map>
</div>

<!-- 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>
</body>
</html>
<!-- [END maps_place_autocomplete_basic_map] -->
32 changes: 32 additions & 0 deletions dist/samples/place-autocomplete-basic-map/docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<!--
@license
Copyright 2025 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_place_autocomplete_basic_map] -->
<html>
<head>
<title>Place Autocomplete map</title>

<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="map-container">
<gmp-basic-place-autocomplete></gmp-basic-place-autocomplete>
<gmp-place-details-compact orientation="horizontal">
<gmp-place-details-place-request></gmp-place-details-place-request>
<gmp-place-all-content></gmp-place-all-content>
</gmp-place-details-compact>
<gmp-map zoom="14" map-id="DEMO_MAP_ID">
<gmp-advanced-marker></gmp-advanced-marker>
</gmp-map>
</div>

<!-- 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>
</body>
</html>
<!-- [END maps_place_autocomplete_basic_map] -->
55 changes: 55 additions & 0 deletions dist/samples/place-autocomplete-basic-map/docs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"use strict";
/*
* @license
* Copyright 2025 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
// [START maps_place_autocomplete_basic_map]
const mapContainer = document.getElementById("map-container");
const autocompleteElement = document.querySelector('gmp-basic-place-autocomplete');
const detailsElement = document.querySelector('gmp-place-details-compact');
const mapElement = document.querySelector('gmp-map');
const advancedMarkerElement = document.querySelector('gmp-advanced-marker');
let center = { lat: 40.749933, lng: -73.98633 }; // New York City
async function initMap() {
//@ts-ignore
const { BasicPlaceAutocompleteElement, PlaceDetailsElement } = await google.maps.importLibrary('places');
//@ts-ignore
const { AdvancedMarkerElement } = await google.maps.importLibrary('marker');
//@ts-ignore
const { LatLngBounds } = await google.maps.importLibrary('core');
// Set the initial map location and autocomplete location bias
mapElement.center = center;
autocompleteElement.locationBias = center;
// Get the underlying google.maps.Map object to add listeners
const map = mapElement.innerMap;
// Add the listener tochange locationBias to locationRestriction when the map moves
map.addListener('bounds_changed', () => {
autocompleteElement.locationBias = null;
autocompleteElement.locationRestriction = map.getBounds();
console.log("bias changed to restriction");
});
// [START maps_place_autocomplete_basic_map_listener]
// Add the listener to update the Place Request element when the user selects a prediction
autocompleteElement.addEventListener('gmp-select', async (event) => {
const placeDetailsRequest = document.querySelector('gmp-place-details-place-request');
placeDetailsRequest.place = event.place.id;
});
// [END maps_place_autocomplete_basic_map_listener]
// Add the listener to update the marker when the Details element loads
detailsElement.addEventListener('gmp-load', async () => {
const location = detailsElement.place.location;
detailsElement.style.display = "block";
advancedMarkerElement.position = location;
advancedMarkerElement.content = detailsElement;
if (detailsElement.place.viewport) {
map.fitBounds(detailsElement.place.viewport);
}
else {
map.setCenter(location);
map.setZoom(17);
}
});
}
initMap();
// [END maps_place_autocomplete_basic_map]
Loading