	function initAutocomplete() {
	  const autocomplete = new google.maps.places.Autocomplete(
		document.getElementById('custServiceAddress'),
		{ types: ['geocode'] }
	  );

	  autocomplete.setFields(['address_component']);

	  autocomplete.addListener('place_changed', () => {
		const place = autocomplete.getPlace();

		let streetNumber = '';
		let streetName = '';
		let city = '';
		let postalTown = '';
		let state = '';
		let zip = '';

		for (const component of place.address_components) {
		  const types = component.types;

		  if (types.includes('street_number')) {
			streetNumber = component.short_name;
		  }

		  if (types.includes('route')) {
			streetName = component.long_name;
		  }

		  if (types.includes('locality')) {
			city = component.long_name;
		  }

		  // UK addresses often don't get a 'locality' at all, Google uses
		  // this separate type (Royal Mail's "post town") instead, so fall
		  // back to it below if 'locality' never showed up.
		  if (types.includes('postal_town')) {
			postalTown = component.long_name;
		  }

		  if (types.includes('administrative_area_level_1')) {
			state = component.short_name;
		  }

		  if (types.includes('postal_code')) {
			zip = component.short_name;
		  }
		}

		if (city === '') {
		  city = postalTown;
		}

		// Combine street number + street name
		const fullAddress = `${streetNumber} ${streetName}`.trim();

		// Fill your custom fields
		document.getElementById('custServiceAddress').value = fullAddress;
		document.getElementById('custServiceCity').value = city;
		document.getElementById('custServiceState').value = state;
		document.getElementById('custServiceZip').value = zip;
	  });
	}
