Best way to set up database structure for advanced filters by city/state/country

I working on the database structure for my app and I will need users to be able to search by location by map and by text (i.e., Miami or Spain). I will need them to be able to search by city , state, country. How do I set this up in the databases? Do I use the “geographic address” option even though this means the user will need to input their address instead of just their city / country? Will I be able to extract the relevant parts of that address later? Or is it better that I collect city and country individually? If so, how do I connect this to an updated list of cities or countries?

Just to be clear, I never want the inputed address to show for other users (other than the one who inputed it) but I do want the city /country to show.

Thanks!

Can anyone support on this?

Yes, you can use the geogrphic address to search for a location. Add your Google API keys and this will suggest address options when using the search input.

You can then store as geographic address and use the :extract function when using the data. You can then extract whatever you need - city, state, country etc.

Hi @s.klaben2

It’s likely that the Google Maps address will solve this for you. I’m going to assume you don’t want to rely on any other third-party API’s. From an address field, you can extract any part of the address you need (Country, City, State, etc). Depending on the address, the field may show up empty (such as trying to extract State in a Country that doesn’t use the state system).

A geographical address search does allow for simple searches like “New York” or “Chicago”. It generally will generate an address close to the city center, and from there you can extract the information you need.

Here you can see the :extract function in action:

image

Awesome super helpful, I will use this. But for the input where the user adds the content - they can technically only add a full address correct? What if I want to collect only the city or country in some situations? Do I still use the geographic address option? How do I make it user friendly so the user doesn’t get confused (for instance, it will say City above the input and in the input it lets them add an address only?)
Thanks!!!

That’s correct. You could choose to extract the geographic city (for example) and store only that value, but I would recommend saving the full address as it’s easy to extract the required information. I’m unsure how you would display the city only in the search box (rather than the full address) . It may be possible by limiting the API, or perhaps via a plugin. Here’s a simple example of how you extract the information you need.

@ZeroqodeSupport’s Google Maps Autocomplete plugin may give you a bit more control over what the user sees, but I can’t say for sure if it will let you show just the city name etc. You’ll have to experiment a bit.

A standard Bubble Search Box will display the full address, yes.