Forum Academy Marketplace Showcase Pricing Features

Distance Calculation of multiple points

In my application I have a function that allows you to create multiple stops for one order. I want to get the distance from the first to the second, then from the second to the third and so on. I would need a function that calculates how many stops there are total and then can repeat with the second option being the first for the next run if that makes sense.

All of the distances then need to be added up to get the full mileage that then can be referenced against my customers preferred rate per mile. that calculation is easy: miles x rate = total.

I am open to using Java within my site, but if you have another idea of how I can accomplish this it would be greatly appreciated.

I currently have maps extended installed but I am a little confused on how it works. I know that I already includes a distance and duration module but I not sure how to make the origin also be the destination.

I may be oversimplifying your issue, but you could have a data table that looks like this:

startGeoAddress endGeoAddress distance

Your rows would look something like:

1423 Main, Chicago 1222 Madison
1222 Madison 8760 Lake Road
8760 Lake Road 654 Harrison

When you add a row, get the last row added and use the “to” address as your “from”. Upon save, you could calculate the difference between the addresses and store it in the distance field.

Then you could just perform a :sum of distance for all the related rows to get your total distance.

I had a feeling I was over complicating it. I’ll give that a try and see if I can get it working.

Thank you for your help.

Quick question, How exactly would you make the table? Should I create it within bubble’s database system or use an external plugin or Airtable?

Thank you again for the help.

I would make 2 tables.

Table name: UserTrips

Fields:
UserID (type text, the unique ID of your user)
TripName (text)

Table name: TripDetails

Fields:
TripID (text, the unique ID of their new trip)
From (type geoaddress, their starting location)
To (.type geoaddress, their end location)
Distance (type number, the calculated miles)

This structure would let your users have multiple trips with unlimited end points.

And I would just create plain Bubble tables.

Thank you, I’ll try to adapt it to my current data base. Thank you again for the help.