Forum Academy Marketplace Showcase Pricing Features

Geographic location defaults to USA

I am saving user addresses as ‘geographic location’ but it keeps defaulting to a US address, rather than a UK (which I need).

Example, I have a dropdown with all UK towns, one of which is Brighton and Hove.

Selecting that makes the database save it as New York, Brighton?

Also, most of the drop down options save fine and they even add a “, UK” extension but how is that possible? Perhaps when a UK town has a similar name to a US town, it defaults to the US one?

Ultimately I would like to offer my users an option to select from a radius close to their home town, wonder if anyone can suggest how to do this?

How are you saving the selected dropdown value to the database (what’s the workflow?) My guess is that you’re currently just using the text value of the selected dropdown item to match to a city, so there’s no way to specify an actual geographic address (other than matching the city name) - there could be many cities with the same name worldwide, hence the inconsistencies you’re having.

I don’t think using static choices is the best way to go here.

If you want to keep things internal then I’d think about using an option set for your list of cities, then you can set the geographic address for each option and not have to worry about mismatching cities with other cities with the same name (it will take a lot of work to set up, depending on how many cities you need to add).

Otherwise you’d be better off using an API to get your cities, then you should be able to set things up to only show results within a radius of the current user’s current location etc.

Thanks for the thoughts. As you guessed, I am currently just using the text value of the selected dropdown item to match to a city.

I realised I don’t know something very basic, how ‘should you’ get an address from a user? I can have an input field in the signup form, but then you are getting a ‘freehand’ address so how does Bubble convert that to long/lat coordinates?

That aside, I quite like the idea of using an option set for the list of cities and setting the geographic address for each option. I have set up an option set called UK Towns, and one option is Barnsley. I got the long/lat numbers by going to Goggle map and right clicking on the town and saving the coordinates, but these will ultimately be very specific (to a single house address) which seems a bit ‘personal’. Not sure how I get the long/lat of a broader area?

I have noticed that when I place a search box and set to geographic address it will auto fill an address based on what the user begins to type. This is brilliant because it ensures the address is spelled correctly. If only I could then save that address in the database, but I can’t get the input from a search box into the database.

Yes, a search box will be much better for you here as you can get the address directly from the Google API, and you haven’t got the hassle of manually creating hundred of options for your option set.

Plus you can set it up to only show UK locations in the search box.

You should be able to save the search box’s value directly to the database (using seachbox's value as the value for the address field).

If only I could then save that address in the database, but I can’t get the input from a search box into the database.

What exactly is the issue you’re having here? It should work as described above (as far as I understand you need to make sure your Google Geocode and Google maps APIs are set up correctly for this to work - so if you haven’t done that yet that’s most likely the issue).

This didn’t work, but that’s probably because I haven’t set up Google Geocode and Google maps APIs - didn’t realise I had to do that. In light of this, I think I would rather manually create hundred of options for my option set. Sounds crazy but I know API’s are way over my head.

I have set up a very simple option set with 3 towns (as a test). See below:

towns

The dropdown displays the 3 towns and uploads to the database fine;

The issue is that the long/lat for Brighton, for example is found on googlemap by right clicking, the actual result is 50.824386197994244, -0.13709095178222735but once enetered into the option set it populates the exact street address;

This may not be an issue though. All I need to do is somehow only display ‘Brighton’ and leave the actual address hidden. So, assume a user created an Event and selected Brighton as the location. From that point on, I should be able to offer the others users a way to search within a radius of their location and only display Brighton Events if within that radius right?

In light of this, I think I would rather manually create hundred of options for my option set.

The Google Maps and Geocode API’s are built into Bubble, so there’s nothing really to set up other than adding your API keys. There’s a full tutorial in the Bubble manual, and it only takes about 10 minutes or so to create your keys in Google Cloud Console.

That said, if you’d rather build your own list of cities then fair enough…

The issue is that the long/lat for Brighton, for example is found on googlemap by right clicking, the actual result is 50.824386197994244, -0.13709095178222735 but once enetered into the option set it populates the exact street address;

There’s no need to use the long/lat for an address field.

You can simply type the name of the city (i.e. ‘brighton and hove’ and press enter, then is should be added to the field:

This may not be an issue though. All I need to do is somehow only display ‘Brighton’ and leave the actual address hidden

Yes, you can extract any part of the geographic address to display in text element (i.e. the city, county, country etc.)

From that point on, I should be able to offer the others users a way to search within a radius of their location and only display Brighton Events if within that radius right?

Yes, but I suspect you’ll need to use the Google Geocode API for that to work.

I just watched the setup video and there’d be a $10/month fee for the API’s, which isn’t much but until my app has some decent visitors I want to avoid any expenses.

That’s how I had it but it was converting Brighton to a USA address. I could simply have a static text link for each town and forget about saving as a geolocation in the database but I really would like to offer the radius search - although you said I would need the Goggle API for that?

Idea: Maybe I could save the lat/long as a number input into the option set so that the user selects ‘Brighton’ but the radius function calls the lat/long data. Can Bubble work out the distances for me without me have Google API?

I just watched the setup video and there’d be a $10/month fee for the API’s, which isn’t much but until my app has some decent visitors I want to avoid any expenses.

There’s a Free tier for Google geocoding, which means you don’t pay anything unless you’re making a lot of calls (i think you get $200 per month of free usage before you’re charged).

That’s how I had it but it was converting Brighton to a USA address.

If I type ‘Brighton and Hove’ into my geographic address option set attribute, it sets it as Brighton & Hove, UK. So I’m not sure why that’s not working for you. If you type ‘Brighton UK’ it should work fine (it does for me).

I could simply have a static text link for each town and forget about saving as a geolocation in the database but I really would like to offer the radius search - although you said I would need the Goggle API for that?

Yes, if you want to use geolocation features (like calculating distances, showing locations on maps, getting location names/addresses etc.) then you need to enable Google Geocoding in your app by adding your Google API keys.
I guess there are ways to manually calculate the distance between two coordinates, so you could just try that (but you’d still have to store the coordinates first in your database or in an option set)

Can Bubble work out the distances for me without me have Google API?

There are other geo location service providers aside from Google, but Google is the one that’s built into Bubble, so doesn’t require any set up (other than adding your API keys).

If you want to use another API service you’d have to set up all the required calls manually to get location details and calculate distances etc.

Alternatively, if you don’t want to use an external location services provider at all, you could just use text fields in either a datatype or an option set to store your city’s data, but that means you won’t be able to use location features (such as calculating distances or displaying addresses on maps etc.), so it depends on what user experience you’re trying to achieve as to the best way to go - but I’d definitely say using Bubble’s built in location features functionality (via Google Geocoding) seems like the simplest and best option to me.

Thanks adamhholmes again for your time and help. I’m going to have a think about this and will decide soon but it’s great to have your input because at least I now know what is (and isn’t) possible.

1 Like

I followed the Bubble tutorial on activating Google API’s for geolocation and I was able to get the API keys sorted. But, from that point on I had the same experience I always have with API’s!

Firstly, the auto complete now didn’t work. I thought that may be because I hadn’t added payment details to Google. I logged into Google and spent a frustrating 20 minutes just trying to find my newly activated API’s (Google UX is terrible). Then, I couldn’t easily see what I would be adding payment too and I got the same old anxiety one get’s when knowing they are well out of their depth!

Long story short, I never want to use an API again! I very much dislike coding and so I will have to find a way to do what I need manually.

1 Like