Do all distance functions in Bubble use Google APIs?

I’m a bit confused. I have a Bubble app on its own domain and with the Google API keys set up.

I have data items with geographic addresses and on a page I return lists of those items searched for and sorted based on “distance”. There are no maps.

I assumed all of the distance functions used Google APIs, but I don’t seem to see them coming through in my Google dashboard’s metrics.

I’d actually be really happy if these functions didn’t use Google APIs as I fear it would become prohibitively expensive - I do a lot of distance stuff but it’s all quite basic. Simple “as the crow flies” (Haversine) distance calculations would be perfectly adequate - I don’t need them to be route based.

Is there any chance the distance search/sort stuff in Bubble uses its own calculations based on latitude and longitue, rather than using Google APIs?

Thanks, James.

1 Like

Hoping someone can help with this. Ideally I’d just like to know what happens behind the scenes when I search for data ‘within 20 miles’ of current page’s location, and when the resulting list is sorted by distance.

Which APIs does it call (if any)? If I have 10 lists on a page with 3 items in each, is that 30 calls to a Google API per page load?

Just to reiterate, I’m not using maps at all, just distances based on geographic addresses.

Thanks.

1 Like

If you need to calculate distance between coordinates, then there are two plugins for it. And you can calculate this dance without any API.

Thanks @shpak.serhiy. Which two plugins are those please?

And can you give me a couple of hints on how to populate a repeating group with e.g. all [things] that are within 20 miles of [this thing]?

James

ToolitKit https://bubble.io/plugin/toolit-kit---helpful-functions-1562812673262x109396480465567740
has distance plugin that calculate distance between two coordinates.

To create a list of all things within 20 miles you need to iterate your list of thing and calculate the distance between every thing from the list and “this thing”. If distance is <20 miles you can store it in a list or mark somehow.

If you have too many things and don’t want to iterate all of them (using API workflow or ListShifter) you could create four separate list of things based on Lon/Lat.

  1. lat > this thing lat
  2. lon > this thing lon
  3. lat < this thing lat
  4. lon > this thing lon

Than you stop iterate the list once you exceed the 20 miles distance and hence you won’t iterate the whole list of things.

Basically, it is a rough algorithm that you can build in Bubble.

1 Like

Hi @shpak.serhiy ,
How can I use the toolit kit plugin to sort a repeating group by distance? The database has the Latitude and Longitude fields. I have struggled to find documentation for the distance function of the plugin. Kindly help.

If the location of the things is stable you could store the distances in the database.

How to do it:

  • Create a new datatype “Relation” that will include reference to two things and a distance field.
  • Create a backend workflow that is triggered when a new thing is added. The workflow should iterate all things and create “Relations”.
  • then you can use “Relation” for sorting.

If it is not your use case and you need to calculate the distance every time within a certain radius then a different a bit more complex approach could be used. It requires more explanation. Let me know you need it.

Thanks for your quick response.
The location of the things (Pharmacy data type) remains the same. However, every time the RG loads, the distance between the Pharmacy and the current user’s location (which changes) has to be calculated and displayed.
My goal is to display that distance in each cell of the RG and sort it by that same distance (closest to furthest).
e.g. Pharmacy A - - - 1.5KM
Pharmacy B - - - 2.3KM
To get the user’s location I used the Toolbox plugin JavascriptToBubble element (with an HTML5 geolocation script) and used the Expression element to compute and display the straight-line distance in the RG cells.
I’d like to avoid creating a distance field that would have to be constantly updated for so many rows.

I guess my question is: Is there a way I could sort the Pharmacy by distance without using the Google Distance Matrix API? Knowing that the distance is already computed and displayed in a Text element in the RG cells.
The Pharmacy data type structure is: Name, Latitude, Longitude

Sorting is possible on the fields of the datatype that set on the RG. The calculated data is not a field and hence is not available for sorting in the RG data source settings.

You can solve this issue by creating a field on the Thing you sort where you will temporary store the distance. You can populate the distance to this field automatically triggering by “When page is loaded” → make change to the list of things (here you indicate the expression that calculates the distance).

Thank you. I’ll apply that.

Hi @shpak.serhiy

I’ve just installed the Ultimate Toolkit :slight_smile: Do I have to have an Encryption Key? If so, do I just make a random key myself?

Thanks!

Not sure if you found the answer to this, just in case, I asked gpt-o after not seeing anything in the forum - thought Id save this here form my reference also.


The encryption key in the “Ultimate Toolkit” plugin for Bubble.io is used for securing sensitive data by encrypting it before storing it in your Bubble.io database or sending it over the network. This helps ensure that even if the data is intercepted or accessed by unauthorized users, it remains unreadable without the proper decryption key.

To get an encryption key, you typically need to generate one using a reliable encryption algorithm. Here’s how you can generate and use an encryption key in Bubble.io with the Ultimate Toolkit plugin:

Step 1: Generating an Encryption Key

You can generate an encryption key using various methods, such as online tools or cryptographic libraries in different programming languages. Here’s a simple way to generate an encryption key using JavaScript:

  1. Using Online Tools:
  • Websites like RandomKeygen can generate secure random keys for you.
  • Select a key type that matches the encryption algorithm you plan to use (e.g., AES-256).
  1. Using JavaScript:
function generateKey(length) {
  let result = '';
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  const charactersLength = characters.length;
  let counter = 0;
  while (counter < length) {
    result += characters.charAt(Math.floor(Math.random() * charactersLength));
    counter += 1;
  }
  return result;
}

const encryptionKey = generateKey(32); // 32 characters for AES-256
console.log(encryptionKey);

Step 2: Using the Encryption Key in Bubble.io

  1. Install the Ultimate Toolkit Plugin:
  • Ensure the Ultimate Toolkit plugin is installed and enabled in your Bubble.io application.
  1. Setting Up the Encryption Key:
  • In the plugin settings, look for the option to input your encryption key.
  • Copy the generated encryption key and paste it into the appropriate field in the plugin settings.
  1. Using Encryption and Decryption Actions:
  • Utilize the plugin’s encryption and decryption actions in your workflows to secure your data.
  • For example, when saving sensitive data, use the encryption action to encrypt the data before saving it to the database.
  • When retrieving sensitive data, use the decryption action to decrypt the data before using it in your application.

Example Workflow:

  1. Encrypting Data Before Saving:
  • In your workflow, add the “Encrypt” action provided by the Ultimate Toolkit plugin.
  • Input the data you want to encrypt and specify the encryption key if required.
  • Save the encrypted data to your database.
  1. Decrypting Data After Retrieving:
  • When you need to use the encrypted data, add the “Decrypt” action in your workflow.
  • Retrieve the encrypted data from your database and input it into the decryption action.
  • Use the decrypted data as needed in your application.

By following these steps, you can generate an encryption key and use it to secure sensitive data in your Bubble.io application with the Ultimate Toolkit plugin.

2 Likes

Thanks Stuart, and GPT :slight_smile:

2 Likes