To validate an address using Address Validation in Maps JavaScript API, call the fetchAddressValidation
      method passing a request body with the address to validate, as shown in the following example.
    
async function validateAddress() { // Import the Address Validation library. const {AddressValidation} = await google.maps.importLibrary('addressValidation'); // Call the fetchAddressValidation method. const result = await AddressValidation.fetchAddressValidation({ address: { postalCode: '94043', regionCode: 'US', languageCode: 'en', addressLines: ['1600 Amphitheatre', 'Parkway'], } }); // Log the results to the console. document.querySelector('pre').textContent = JSON.stringify(result, null, ' '); }
You can define an address by using individual components, or by using addressLines
      to pass the entire formatted address as an array literal (the API will parse the address
      into individual components):
address: { addressLines: ['1600 Amphitheatre Parkway, Mountain View, CA 94043'], }
Handle the results
The fetchAddressValidation method returns a promise that resolves to an
      AddressValidationResponse object. This object contains the validated address,
      including any corrections made by the API. You can access the various fields of the
      response object to determine the validation status of the address. The following example
      shows how to access the fields of the response object.
    
async function validateAddress() { // Import the Address Validation library. const {AddressValidation} = await google.maps.importLibrary('addressValidation'); // Call the fetchAddressValidation method. const result = await AddressValidation.fetchAddressValidation({ address: { postalCode: '94043', regionCode: 'US', languageCode: 'en', addressLines: ['1600 Amphitheatre', 'Parkway'], } }); // Log the results to the console: console.log(`Formatted address: ${result.address.formattedAddress}`); console.log(`Entered: ${result.verdict.inputGranularity}`); console.log(`Validated: ${result.verdict.validationGranularity}`); console.log(`Address complete: ${result.verdict.addressComplete}`); console.log(`Has unconfirmed components: ${result.verdict.hasUnconfirmedComponents}`); console.log(`Has inferred components: ${result.verdict.hasInferredComponents}`); console.log(`Has replaced components: ${result.verdict.hasReplacedComponents}`); }