For those that have implemented address autocomplete on forms, I’m wondering how you are parsing the address components? With the Place api call, you get back the formatted_address among other things. Are you parsing this string to break down the values into discrete Street/City/State/Zip values, or are you doing another API call to get the address_components using Place Details or Geocode?
The address_components response seems a bit complex to parse since the number of components in the result is not consistent
In case someone else needs this, I found some JS that seems to do the trick. After the Google Geocode api call to get the Places ID details, I update a variable with the flow action result (response from Google) with this code:
// Access the address_components from the global context
const address_components = **ADDRESS_COMPONENTS REFERENCE GOES HERE**;
// Check if address_components exists
if (address_components) {
// Reduce the address_components array to an object with keys as types and values as long_name
const address = address_components.reduce((seed, { long_name, types }) => {
types.forEach(t => {
seed[t] = long_name;
});
return seed;
}, {});
// Return the final address object
return address;
} else {
// If address_components does not exist, return an empty object
return {};
}
The updated variable now contains an array like this that can be referenced elsewhere using dot notation: