Skip to content

Commit 509df9d

Browse files
Update dist folder [skip ci] (#356)
Co-authored-by: googlemaps-bot <[email protected]>
1 parent e8c1021 commit 509df9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+7321
-0
lines changed

dist/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ <h1>Maps JSAPI Samples</h1>
3232
<li><a href='/samples/3d-simple-map-declarative/dist'>3d-simple-map-declarative</a></li>
3333
<li><a href='/samples/3d-simple-marker/dist'>3d-simple-marker</a></li>
3434
<li><a href='/samples/add-map/dist'>add-map</a></li>
35+
<li><a href='/samples/address-validation/dist'>address-validation</a></li>
3536
<li><a href='/samples/advanced-markers-animation/dist'>advanced-markers-animation</a></li>
3637
<li><a href='/samples/deckgl-heatmap/dist'>deckgl-heatmap</a></li>
3738
<li><a href='/samples/deckgl-kml/dist'>deckgl-kml</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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
First `cd` to the folder for the sample to run, then:
15+
16+
`$npm start`
17+
18+
### Build an individual example
19+
20+
From `samples/`:
21+
22+
`$npm run build --workspace=sample-name/`
23+
24+
### Build all of the examples.
25+
26+
From `samples/`:
27+
`$npm run build-all`
28+
29+
## Feedback
30+
31+
For feedback related to this sample, please open a new issue on
32+
[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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_address_validation]-->
8+
<html>
9+
<head>
10+
<title>Address Validation</title>
11+
12+
<link rel="stylesheet" type="text/css" href="./style.css" />
13+
<script type="module" src="./index.js"></script>
14+
</head>
15+
<body>
16+
<!-- Address Validation Form Container -->
17+
<div id="sidebar">
18+
<!-- Header -->
19+
<div class="sidebar-header">
20+
<h2>Address Validation</h2>
21+
</div>
22+
<!-- Content: Address Form -->
23+
<form id="address-form" class="sidebar-content" autocomplete="off">
24+
<!-- Example Dropdown Section -->
25+
<div id="example-dropdown-container" style="margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid #e5e7eb;">
26+
<label for="example-select" style="margin-bottom: 0.5rem;">Load Example Address:</label>
27+
<select id="example-select" name="exampleSelect" class="form-select">
28+
<option value="" selected disabled>-- Select an Example --</option>
29+
<option value="google">Valid Address</option>
30+
<option value="nonExistentSubpremise">Non-existent Subpremise</option>
31+
<option value="missingSubpremise">Missing Subpremise</option>
32+
<option value="misspelledLocality">Misspelled Locality</option>
33+
<option value="missingLocality">Missing Locality</option>
34+
<option value="usPoBox">US PO Box</option>
35+
</select>
36+
</div>
37+
<div>
38+
<label for="street-address-1">Street Address 1</label>
39+
<input
40+
id="street-address-1"
41+
name="streetAddress1"
42+
type="text"
43+
placeholder="e.g., 1600 Amphitheatre Parkway"
44+
/>
45+
</div>
46+
<div>
47+
<label for="street-address-2">Street Address 2 (Optional)</label>
48+
<input
49+
id="street-address-2"
50+
name="streetAddress2"
51+
type="text"
52+
placeholder="e.g., Suite 100"
53+
/>
54+
</div>
55+
<!-- Use a div with grid class for City/State/ZIP layout -->
56+
<div class="form-grid-triple">
57+
<div>
58+
<label for="city">City</label>
59+
<input id="city" name="city" type="text" placeholder="e.g., Mountain View" />
60+
</div>
61+
<div>
62+
<label for="state">State or territory</label>
63+
<input id="state" name="state" type="text" placeholder="e.g., CA" />
64+
</div>
65+
<div>
66+
<label for="zip-code">ZIP Code</label>
67+
<input id="zip-code" name="zipCode" type="text" placeholder="e.g., 94043" />
68+
</div>
69+
</div>
70+
<div id="region-select-container">
71+
<div>
72+
<label for="region-select">Region</label>
73+
<select id="region-select" name="regionSelect" class="form-select">
74+
<option value="AR">Argentina</option>
75+
<option value="AU">Australia</option>
76+
<option value="AT">Austria</option>
77+
<option value="BE">Belgium</option>
78+
<option value="BR">Brazil</option>
79+
<option value="BG">Bulgaria</option>
80+
<option value="CA">Canada</option>
81+
<option value="CL">Chile</option>
82+
<option value="CO">Colombia</option>
83+
<option value="HR">Croatia</option>
84+
<option value="CZ">Czechia</option>
85+
<option value="DK">Denmark</option>
86+
<option value="EE">Estonia</option>
87+
<option value="FI">Finland</option>
88+
<option value="FR">France</option>
89+
<option value="DE">Germany</option>
90+
<option value="HU">Hungary</option>
91+
<option value="IN">India</option>
92+
<option value="IE">Ireland</option>
93+
<option value="IT">Italy</option>
94+
<option value="JP">Japan</option>
95+
<option value="LV">Latvia</option>
96+
<option value="LT">Lithuania</option>
97+
<option value="LU">Luxembourg</option>
98+
<option value="MY">Malaysia</option>
99+
<option value="MX">Mexico</option>
100+
<option value="NL">Netherlands</option>
101+
<option value="NO">Norway</option>
102+
<option value="NZ">New Zealand</option>
103+
<option value="PL">Poland</option>
104+
<option value="PT">Portugal</option>
105+
<option value="PR">Puerto Rico</option>
106+
<option value="SG">Singapore</option>
107+
<option value="SK">Slovakia</option>
108+
<option value="SI">Slovenia</option>
109+
<option value="ES">Spain</option>
110+
<option value="SE">Sweden</option>
111+
<option value="CH">Switzerland</option>
112+
<option value="GB">United Kingdom</option>
113+
<option value="US" selected>United States</option>
114+
<option value="">Unknown</option>
115+
</select>
116+
</div>
117+
</div>
118+
119+
<button id="validate-button" type="submit">Validate Address</button>
120+
121+
<button id="clear-form-button" type="button" event="handleClearForm">Clear Form</button>
122+
123+
<!-- Result Display Area -->
124+
<div id="result-container">
125+
<label for="result-display">Validation Result (formatted address and JSON)</label>
126+
<pre id="result-display">Result will appear here...</pre>
127+
</div>
128+
</form>
129+
</div>
130+
<!-- prettier-ignore -->
131+
<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))})
132+
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "beta"});</script>
133+
</body>
134+
</html>
135+
<!--[END maps_address_validation]-->
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/*
2+
* @license
3+
* Copyright 2025 Google LLC. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// [START maps_address_validation]
8+
// --- DOM Refs ---
9+
const addressForm = document.getElementById('address-form');
10+
const validateButton = document.getElementById('validate-button');
11+
const clearFormButton = document.getElementById('clear-form-button');
12+
const resultDisplay = document.getElementById('result-display');
13+
const loadingText = document.getElementById('loading-text');
14+
// --- Input field refs ---
15+
const streetAddress1Input = document.getElementById('street-address-1') as HTMLInputElement;
16+
const streetAddress2Input = document.getElementById('street-address-2') as HTMLInputElement;
17+
const cityInput = document.getElementById('city') as HTMLInputElement;
18+
const stateInput = document.getElementById('state') as HTMLInputElement;
19+
const zipCodeInput = document.getElementById('zip-code') as HTMLInputElement;
20+
const regionSelect = document.getElementById('region-select') as HTMLSelectElement;
21+
const exampleSelect = document.getElementById('example-select') as HTMLSelectElement;
22+
23+
// --- Core Initialization ---
24+
async function init() {
25+
// Load the Address Validation library
26+
await google.maps.importLibrary('addressValidation');
27+
// Set event listeners
28+
addressForm!.addEventListener('submit', handleValidationSubmit);
29+
exampleSelect!.addEventListener('change', handleExampleSelectChange);
30+
clearFormButton!.addEventListener('click', handleClearForm);
31+
}
32+
33+
// [START maps_address_validation_form_handler]
34+
// --- Validation Handler ---
35+
async function handleValidationSubmit(event) {
36+
event.preventDefault(); // Prevent default form submission
37+
resultDisplay!.textContent = 'Validating...'; // Clear previous results
38+
39+
// Validate the address
40+
try {
41+
//@ts-ignore
42+
const result = await google.maps.addressValidation.AddressValidation.fetchAddressValidation({
43+
address: {
44+
regionCode: regionSelect!.value.trim(),
45+
languageCode: 'en',
46+
addressLines: [
47+
streetAddress1Input!.value.trim(),
48+
streetAddress2Input!.value.trim()
49+
].filter(line => line), // Filter out empty lines
50+
locality: cityInput!.value.trim(),
51+
administrativeArea: stateInput!.value.trim(),
52+
postalCode: zipCodeInput!.value.trim(),
53+
},
54+
});
55+
56+
resultDisplay!.textContent =
57+
"Verdict summary\n================\n" +
58+
`Formatted address: ${result.address.formattedAddress}\n` +
59+
`Entered: ${result.verdict.inputGranularity}\n` +
60+
`Validated: ${result.verdict.validationGranularity}\n` +
61+
`Geocoded: ${result.verdict.geocodeGranularity}\n\n` +
62+
`${getVerdictMessage(result.verdict, 'addressComplete')}\n` +
63+
`${getVerdictMessage(result.verdict, 'hasUnconfirmedComponents')}\n` +
64+
`${getVerdictMessage(result.verdict, 'hasInferredComponents')}\n` +
65+
`${getVerdictMessage(result.verdict, 'hasReplacedComponents')}\n\n` +
66+
`Raw JSON response\n=================\n` +
67+
JSON.stringify(result, null, ' ');
68+
69+
} catch (error) {
70+
console.error('Validation failed:', error);
71+
if (error instanceof Error) {
72+
resultDisplay!.textContent = `Error: ${error.message}`;
73+
}
74+
}
75+
}
76+
// [END maps_address_validation_form_handler]
77+
78+
// --- Verdict Messages ---
79+
const verdictMessages = {
80+
addressComplete: {
81+
trueMessage:
82+
'- The API found no unresolved, unexpected, or missing address elements.',
83+
falseMessage:
84+
'- At least one address element is unresolved, unexpected, or missing.',
85+
},
86+
hasUnconfirmedComponents: {
87+
trueMessage: '- The API can\'t confirm at least one address component.',
88+
falseMessage: '- The API confirmed all address components.',
89+
},
90+
hasInferredComponents: {
91+
trueMessage: '- The API inferred (added) at least one address component.',
92+
falseMessage: '- The API did not infer (add) any address components.',
93+
},
94+
hasReplacedComponents: {
95+
trueMessage: '- The API replaced at least one address component.',
96+
falseMessage: '- The API did not replace any address components.',
97+
},
98+
};
99+
100+
// Helper function to get the verdict message for a given verdict key
101+
function getVerdictMessage(verdict, key) {
102+
if (!verdict || !verdictMessages[key]) return 'Unknown';
103+
return verdict[key] ? verdictMessages[key].trueMessage :
104+
verdictMessages[key].falseMessage;
105+
}
106+
107+
// Handler for Dropdown Change
108+
function handleExampleSelectChange(event) {
109+
const selectedValue = event.target.value; // e.g., "google", "suite", ""
110+
if (selectedValue && examples[selectedValue]) {
111+
populateAddressFields(examples[selectedValue]);
112+
} else if (!selectedValue) {
113+
// Optional: Clear fields if the "-- Select --" option is chosen
114+
populateAddressFields(null); // Pass null to clear fields
115+
}
116+
}
117+
118+
// Clear Form Handler
119+
function handleClearForm() {
120+
streetAddress1Input!.value = '';
121+
streetAddress2Input!.value = '';
122+
cityInput!.value = '';
123+
stateInput!.value = '';
124+
zipCodeInput!.value = '';
125+
regionSelect!.value = '';
126+
exampleSelect!.value = '';
127+
resultDisplay!.textContent = 'Result will appear here...';
128+
console.log('Cleared form');
129+
}
130+
131+
// Example Address Data
132+
const examples = {
133+
google: {
134+
streetAddress1: '1600 Amphitheatre Parkway',
135+
streetAddress2: '', // Explicitly empty
136+
city: 'Mountain View',
137+
state: 'CA',
138+
zipCode: '94043',
139+
region: 'US'
140+
},
141+
nonExistentSubpremise: {
142+
streetAddress1: '2930 Pearl St.',
143+
streetAddress2: 'Suite 100',
144+
city: 'Boulder',
145+
state: 'CO',
146+
zipCode: '', // Explicitly empty
147+
region: 'US'
148+
},
149+
missingSubpremise: {
150+
streetAddress1: '500 West 2nd Street',
151+
streetAddress2: null, // Can use null or undefined too
152+
city: 'Austin',
153+
state: 'TX',
154+
zipCode: '78701',
155+
region: 'US'
156+
},
157+
misspelledLocality: {
158+
streetAddress1: '1600 Amphitheatre Pkwy',
159+
streetAddress2: '',
160+
city: 'Montan View',
161+
state: 'CA',
162+
zipCode: '94043',
163+
region: 'US'
164+
},
165+
missingLocality: {
166+
streetAddress1: 'Brandschenkestrasse 110 8002',
167+
streetAddress2: '',
168+
city: '',
169+
state: '',
170+
zipCode: '',
171+
region: ''
172+
},
173+
usPoBox: {
174+
streetAddress1: 'PO Box 1108',
175+
streetAddress2: '',
176+
city: 'Sterling',
177+
state: 'VA',
178+
zipCode: '20166-1108',
179+
region: 'US'
180+
},
181+
};
182+
183+
// Helper function to populate form fields with example address data
184+
function populateAddressFields(exampleAddress) {
185+
if (!exampleAddress) {
186+
console.warn("No example address data provided.");
187+
return;
188+
}
189+
190+
// Get values from example, providing empty string as default
191+
streetAddress1Input!.value = exampleAddress.streetAddress1 || '';
192+
streetAddress2Input!.value = exampleAddress.streetAddress2 || '';
193+
cityInput!.value = exampleAddress.city || '';
194+
stateInput!.value = exampleAddress.state || '';
195+
zipCodeInput!.value = exampleAddress.zipCode || '';
196+
regionSelect!.value = exampleAddress.region || '';
197+
198+
// Clear previous results and errors
199+
resultDisplay!.textContent = 'Result will appear here...';
200+
201+
console.log("Populated fields with example:", exampleAddress);
202+
}
203+
204+
init();
205+
// [END maps_address_validation]

0 commit comments

Comments
 (0)