google map update

change geocode to address.
update switch to cover if street_address is available.
This commit is contained in:
Bill Richardson 2024-06-06 10:08:51 -04:00
parent 963dda5a77
commit 8a7c7bda23

View file

@ -195,7 +195,7 @@ export default {
this.autocomplete = new window.google.maps.places.Autocomplete(document.getElementById('autocomplete'), {
componentRestrictions: { country: ['us'] },
fields: ['address_components'],
types: ['geocode']
types: ['address']
});
// Set up the Autocomplete place_changed event to call our method to fill in the address
@ -229,16 +229,30 @@ export default {
this.$nextTick(() => {
this.showAllFields = true;
// eslint-disable-next-line no-restricted-syntax
let processedStreetAddress = false;
let processedRoute = false;
for (const component of googlePlace.address_components) {
const componentType = component.types[0];
switch (componentType) {
case 'street_number': {
self.addressModel.streetAddress = component.long_name;
if (processedRoute) {
self.addressModel.streetAddress = `${component.long_name} ${self.addressModel.streetAddress}`;
} else {
self.addressModel.streetAddress = component.long_name;
}
processedStreetAddress = true;
break;
}
case 'route': {
self.addressModel.streetAddress += ` ${component.short_name}`;
if (processedStreetAddress) {
self.addressModel.streetAddress += ` ${component.short_name}`;
} else {
self.addressModel.streetAddress = component.short_name;
}
processedRoute = true;
break;
}
case 'locality': {