Skip to content

Commit ae6a40c

Browse files
Update dist folder [skip ci] (#910)
1 parent 32c236f commit ae6a40c

File tree

21 files changed

+1113
-0
lines changed

21 files changed

+1113
-0
lines changed

dist/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ <h1>Maps JSAPI Samples</h1>
6969
<li><a href='/samples/place-class/dist'>place-class</a></li>
7070
<li><a href='/samples/place-nearby-search/dist'>place-nearby-search</a></li>
7171
<li><a href='/samples/place-text-search/dist'>place-text-search</a></li>
72+
<li><a href='/samples/places-autocomplete-addressform/dist'>places-autocomplete-addressform</a></li>
7273
<li><a href='/samples/react-ui-kit-place-details/dist'>react-ui-kit-place-details</a></li>
7374
<li><a href='/samples/react-ui-kit-place-details-compact/dist'>react-ui-kit-place-details-compact</a></li>
7475
<li><a href='/samples/react-ui-kit-place-details-latlng/dist'>react-ui-kit-place-details-latlng</a></li>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": [
3+
"plugin:@typescript-eslint/recommended"
4+
],
5+
"parser": "@typescript-eslint/parser",
6+
"rules": {
7+
"@typescript-eslint/ban-ts-comment": 0,
8+
"@typescript-eslint/no-this-alias": 1,
9+
"@typescript-eslint/no-empty-function": 1,
10+
"@typescript-eslint/explicit-module-boundary-types": 1,
11+
"@typescript-eslint/no-unused-vars": 1
12+
}
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Google Maps JavaScript Sample
2+
3+
This sample is generated from @googlemaps/js-samples located at
4+
https://github.com/googlemaps-samples/js-api-samples.
5+
6+
## Setup
7+
8+
### Before starting run:
9+
10+
`npm i`
11+
12+
### Run an example on a local web server
13+
14+
`cd samples/places-autocomplete-addressform`
15+
`npm start`
16+
17+
### Build an individual example
18+
19+
`cd samples/places-autocomplete-addressform`
20+
`npm run build`
21+
22+
From 'samples':
23+
24+
`npm run build --workspace=places-autocomplete-addressform/`
25+
26+
### Build all of the examples.
27+
28+
From 'samples':
29+
30+
`npm run build-all`
31+
32+
### Run lint to check for problems
33+
34+
`cd samples/places-autocomplete-addressform`
35+
`npx eslint index.ts`
36+
37+
## Feedback
38+
39+
For feedback related to this sample, please open a new issue on
40+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<!--
3+
@license
4+
Copyright 2025 Google LLC. All Rights Reserved.
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<!-- [START maps_places_autocomplete_addressform] -->
8+
<html>
9+
<head>
10+
<title>Place Autocomplete Address Form</title>
11+
12+
<link
13+
href="https://fonts.googleapis.com/css?family=Roboto:400,500"
14+
rel="stylesheet" />
15+
16+
<link rel="stylesheet" type="text/css" href="./style.css" />
17+
<script type="module" src="./index.js"></script>
18+
<!-- prettier-ignore -->
19+
<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))})
20+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
21+
</head>
22+
<body>
23+
<!-- Note: The address components in this sample are based on North American address format.
24+
You might need to adjust them for the locations relevant to your app. For more information, see
25+
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
26+
-->
27+
28+
<form id="address-form" action="" method="get" autocomplete="off">
29+
<p class="title">Sample address form for North America</p>
30+
<p class="note"><em>* = required field</em></p>
31+
<label class="full-field">
32+
<span class="form-label">Deliver to*</span>
33+
<gmp-place-autocomplete
34+
included-primary-types="street_address"
35+
included-region-codes="US"></gmp-place-autocomplete>
36+
</label>
37+
<label class="full-field">
38+
<span class="form-label">Street address*</span>
39+
<input id="address1" name="address1" />
40+
</label>
41+
<label class="full-field">
42+
<span class="form-label">Apartment, unit, suite, or floor #</span>
43+
<input id="address2" name="address2" />
44+
</label>
45+
<label class="full-field">
46+
<span class="form-label">City*</span>
47+
<input id="locality" name="locality" required />
48+
</label>
49+
<div class="address-row">
50+
<label class="slim-field-left">
51+
<span class="form-label">State/Province*</span>
52+
<input id="state" name="state" required />
53+
</label>
54+
<label class="slim-field-right">
55+
<span class="form-label">Postal code*</span>
56+
<input id="postcode" name="postcode" required />
57+
</label>
58+
</div>
59+
<label class="full-field">
60+
<span class="form-label">Country/Region*</span>
61+
<input id="country" name="country" required />
62+
</label>
63+
<button type="button" class="my-button">Save address</button>
64+
65+
<!-- Reset button provided for development testing convenience.
66+
Not recommended for user-facing forms due to risk of mis-click when aiming for Submit button. -->
67+
<input type="reset" value="Clear form" />
68+
</form>
69+
</body>
70+
</html>
71+
<!-- [END maps_places_autocomplete_addressform] -->
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_places_autocomplete_addressform]
8+
// This sample uses the Places Autocomplete widget to:
9+
// 1. Help the user select a place
10+
// 2. Retrieve the address components associated with that place
11+
// 3. Populate the form fields with those address components.
12+
// This sample requires the Places library, Maps JavaScript API.
13+
14+
let placeAutocomplete;
15+
let address1Field: HTMLInputElement;
16+
let address2Field: HTMLInputElement;
17+
let postalField: HTMLInputElement;
18+
19+
async function initAutocomplete() {
20+
const { Place, Autocomplete } = (await google.maps.importLibrary(
21+
'places'
22+
)) as google.maps.PlacesLibrary;
23+
24+
placeAutocomplete = document.querySelector(
25+
'gmp-place-autocomplete'
26+
) as google.maps.places.PlaceAutocompleteElement;
27+
address1Field = document.querySelector('#address1') as HTMLInputElement;
28+
address2Field = document.querySelector('#address2') as HTMLInputElement;
29+
postalField = document.querySelector('#postcode') as HTMLInputElement;
30+
const saveButton = document.querySelector('.my-button') as HTMLButtonElement;
31+
32+
placeAutocomplete.focus();
33+
34+
// Handle user selection on the autocomplete widget.
35+
placeAutocomplete.addEventListener(
36+
'gmp-select',
37+
async ({ placePrediction }) => {
38+
fillInAddress(placePrediction);
39+
}
40+
);
41+
42+
saveButton.addEventListener('click', () => {
43+
// Display a message when the Save button is clicked.
44+
alert('In a real application, this would save the address details.');
45+
});
46+
}
47+
48+
// [START maps_places_autocomplete_addressform_fillform]
49+
async function fillInAddress(placePrediction) {
50+
// The placePrediction object does not have all the details needed
51+
// for the form, so we'll call fetchFields to get the place details.
52+
const { Place } = (await google.maps.importLibrary(
53+
'places'
54+
)) as google.maps.PlacesLibrary;
55+
const place = placePrediction.toPlace();
56+
await place.fetchFields({ fields: ['addressComponents'] });
57+
58+
let address1 = '';
59+
let postcode = '';
60+
61+
if (!place.addressComponents) {
62+
return;
63+
}
64+
65+
// Populate form fields with address component data.
66+
// The field is only updated if the types array includes
67+
// the specified type-value.
68+
for (const component of place.addressComponents) {
69+
if (component.types.includes('street_address')) {
70+
address1 = `${component.longText} ${address1}`;
71+
}
72+
73+
if (component.types.includes('street_number')) {
74+
address1 = `${component.longText} ${address1}`;
75+
}
76+
77+
if (component.types.includes('route')) {
78+
address1 += component.shortText;
79+
}
80+
81+
if (component.types.includes('postal_code')) {
82+
postcode = `${component.longText}${postcode}`;
83+
}
84+
85+
if (component.types.includes('postal_code_suffix')) {
86+
postcode = `${postcode}-${component.longText}`;
87+
}
88+
89+
if (component.types.includes('locality')) {
90+
(document.querySelector('#locality') as HTMLInputElement).value =
91+
component.longText!;
92+
}
93+
94+
if (component.types.includes('administrative_area_level_1')) {
95+
(document.querySelector('#state') as HTMLInputElement).value =
96+
component.shortText!;
97+
}
98+
99+
if (component.types.includes('country')) {
100+
(document.querySelector('#country') as HTMLInputElement).value =
101+
component.longText!;
102+
}
103+
}
104+
105+
address1Field.value = address1;
106+
postalField.value = postcode;
107+
108+
// After filling the form with address components from the Autocomplete
109+
// prediction, set cursor focus on the second address line to encourage
110+
// entry of subpremise information such as apartment, unit, or floor number.
111+
address2Field.focus();
112+
}
113+
// [END maps_places_autocomplete_addressform_fillform]
114+
115+
initAutocomplete();
116+
// [END maps_places_autocomplete_addressform]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@js-api-samples/places-autocomplete-addressform",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "tsc && bash ../jsfiddle.sh places-autocomplete-addressform && bash ../app.sh places-autocomplete-addressform && bash ../docs.sh places-autocomplete-addressform && npm run build:vite --workspace=. && bash ../dist.sh places-autocomplete-addressform",
6+
"test": "tsc && npm run build:vite --workspace=.",
7+
"start": "tsc && vite build --base './' && vite",
8+
"build:vite": "vite build --base './'",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
13+
}
14+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* [START maps_places_autocomplete_addressform] */
7+
/*
8+
* Optional: Makes the sample page fill the window.
9+
*/
10+
html,
11+
body {
12+
height: 100%;
13+
margin: 0;
14+
padding: 0;
15+
}
16+
17+
body {
18+
font-family: 'Roboto', sans-serif;
19+
font-size: 18px;
20+
color: rgb(104, 104, 104);
21+
}
22+
23+
form {
24+
display: flex;
25+
flex-wrap: wrap;
26+
align-items: center;
27+
max-width: 400px;
28+
padding: 20px;
29+
margin: 5px;
30+
border: 2px solid #adacac;
31+
border-radius: 5px;
32+
}
33+
34+
input {
35+
width: 100%;
36+
margin-top: 0;
37+
padding: 0.5em;
38+
border: 0;
39+
border-bottom: 2px solid gray;
40+
font-family: 'Roboto', sans-serif;
41+
font-size: 18px;
42+
}
43+
44+
input[type='reset'] {
45+
width: auto;
46+
height: auto;
47+
border-bottom: 0;
48+
background-color: transparent;
49+
color: rgb(104, 104, 104);
50+
font-size: 14px;
51+
margin: 20px 20px 0 0;
52+
cursor: pointer;
53+
}
54+
55+
.title {
56+
width: 100%;
57+
margin-block-end: 0;
58+
font-weight: 500;
59+
margin: 0;
60+
}
61+
62+
.note {
63+
width: 100%;
64+
margin-block-start: 0;
65+
font-size: 12px;
66+
}
67+
68+
.form-label {
69+
width: 100%;
70+
padding: 0.5em;
71+
}
72+
73+
.full-field {
74+
flex: 400px;
75+
margin: 15px 15px 0 0;
76+
}
77+
78+
.address-row {
79+
display: flex;
80+
width: 95%;
81+
gap: 1.5em; /* Add space between the two fields */
82+
padding-bottom: 0;
83+
}
84+
85+
.slim-field-left {
86+
flex-grow: 1;
87+
margin: 15px 0;
88+
}
89+
90+
.slim-field-right {
91+
flex-grow: 1;
92+
margin: 15px 0;
93+
}
94+
95+
.my-button {
96+
background-color: #000;
97+
border-radius: 6px;
98+
color: #fff;
99+
margin-top: 20px;
100+
cursor: pointer;
101+
padding: 6px 24px;
102+
text-decoration: none;
103+
}
104+
/* [END maps_places_autocomplete_addressform] */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"strict": true,
6+
"noImplicitAny": false,
7+
"lib": [
8+
"es2015",
9+
"esnext",
10+
"es6",
11+
"dom",
12+
"dom.iterable"
13+
],
14+
"moduleResolution": "Node",
15+
"jsx": "preserve"
16+
}
17+
}

dist/samples/places-autocomplete-addressform/dist/assets/index-D7PTA2jX.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)