Is it possible to pass location to Bubble API to get closest addresses?

I have a Thing called “Addresses” in Bubble with 2 columns: latitude,longitude coordinates in the first column and address in the second column.

I’d like to pass the user’s current latitude, longitude to the Bubble API to search my Addresses and return the top 8 addresses within a certain radius or the top 8 closest addresses.

I don’t see a way to do this in the Bubble documentation so it may not be possible. Does anyone have any ideas?

If not, I may have to spin up a MySql database, create an API to run this query, and then have Bubble ping the API using the API Connector whenever I need this data. However, this complicates the architecture and forces me to keep two separate databases now that must sync.

If you convert lat/long to an address then you can search for addresses that are within X miles or sorted by distance to achieve what you want.

1 Like

AH. Thanks for pointing me in the right direction. I see now there’s a constraint type I can use to search the Bubble API called “geographic_search”.

Having trouble with the constraint value syntax though. In the Bubble editor “within 0.06km of address” works, but that doesn’t work in the API.

Tried these variations but still haven’t cracked it:

  • [ { “key”: “address”, “constraint_type”: “geographic_search”, “value”: "within 0.06 km of 1288 Massachusetts Ave, Cambridge, MA 02138” }]

  • [ { “key”: “address”, “constraint_type”: “geographic_search”, “value”: "0.06 km, 1288 Massachusetts Ave, Cambridge, MA 02138” }]

  • [ { “key”: “address”, “constraint_type”: “geographic_search”, “value”: “0.06 km”, “value”:"1288 Massachusetts Ave, Cambridge, MA 02138” }]

  • [ { “key”: “address”, “constraint_type”: “geographic_search”, “value”: [“0.06 km”, "1288 Massachusetts Ave, Cambridge, MA 02138”] }]

UGH. thought this worked, but it just returned all address. This almost worked…

[{“key”: “address”,“constraint_type”:“geographic_search”,“value”: {“address”: “1288 Massachusetts Ave, Cambridge, MA 02138”,“range”: “0.06 km”}}]

The support team came up with a way to do this – sharing here in case anyone else encounters this issue down the line.

  1. create a back end workflow and add two parameters. The first is the addresses your user is at. The second is the distance you want to to search.

  2. Add an action to return data from api where they key is address searching for the database where you keep your addresses and returning as a list. Then perform the search using the parameters received from the GET request.

  3. test in postman and see desired results