Store Address Components to DB from Google Autocomplete

Hi, I am trying to get the components of an address returned by the Google Places Autocomplete component. I’ll store the returned values to a database table and probably use them to populate a couple UI fields along the way.

I’ve reviewed the Google pages that are linked from help on the Google API Codeless objects. I have an ok understanding of the structure of a place details request but am having trouble getting the syntax correct.

Is there an existing blog post or video showing a simple example of how we can pull out the address_components (e.g. city, state, postal code, etc) so that they can then be used in either UI components or saved to a database table?

Thanks!

Hi @James_Hereford ,

I will need a little time to answer your question.
Thanks for understanding.

Regards,
Sergey

Thanks for waiting,
The first thing you need to do is add an “ID” for your component if it doesn’t already exist. After which you will have actions of this component, in which you can get detailed information. I am attaching screenshots.
To add to the database you can use the method with “Data API” → “Save Object In Backendless”

If there are any difficulties, we will be happy to help.

Regards,
Sergey


Thanks! This is super helpful. I was trying to save place_id to the data model first and then reference it.

Another follow-up, mainly to help me understand how to work with Objects better. Consider the following:


How can I access the individual elements of the object once it’s stored in to the form’s data model? I expected place_details.postal_code to return an object with the long_name and short_name of postal_Code but it came back undefined. I tried nesting Get Property of blocks as well but couldn’t quite get it.

Just FYI, one of my side goals here is to understand how to populate additional fields on the page for street address, city, state, and zipcode based on what the user selects in the autocomplete field.

Thanks again!

Hi, @James_Hereford

The property address_components is an array, so first you need to find the necessary object in the list. For example, to get an object with a postal_code type, try to add the following codeless blocks, with "formAddFacility" Data block instead Page Data

Then you can get long_name and short_name values from the returned result using a block Get Property of.

Regards,
Serhiy

Awesome, thank you! I’ll try this today and let you know if I run into any issues.