Sort by distance away crashes

Hi all,

So I have a data table with about 4500 hospitals on it.

When the user enters the app, it asks for permission to get their location.

That’s then used to fill the “distance from user” column.

I want a screen to display hospitals in order from closest to furthest. I only need to display the 8 or so closest.

However it seems to crash the app every time, or display the rows that are at the top of the sheet, instead of those closest. I suppose it’s because it’s calculating the distance from every row but hasn’t updated yet.

Is there a workaround? If tried adding a filter to the collection for only hospitals that are <50 miles, but the same happens.

Is it maybe having trouble calculating distance for some reason? Have you tried different devices?

1 Like

I have, it’s slower on mobile. I’m guessing it;'s because there’s 4500 rows to calculate for, is that a correct assumption or shouldn’t be a problem? Thanks Jeff.

I haven’t tried to calculate distance for that many rows all at once, but I’d guess that this could lead to performance issues. What if you first had the user filter the list by another variable, like City for example, then only calculate the distance for that filtered list of results…?


Yeah I’ve never used distance for that many rows either. At most a handful of rows for me. It probably takes a few seconds to first aquire your current location and then use that to calculate distance on 4500 rows. Then as soon as your location changes, it has to update all of those rows again, and it continues over and over as long as you are using a user’s live location. That ends up being a lot of continuous processing that happens over and over every few seconds.

It would probably improve performance if you maybe had an Edit form where a user enters an address or aquires coordinates, and then submit the form to write that location to a basic column. That way it becomes more of a static location that’s not continuously changing. Then use that basic column location value to calculate distance. It wouldn’t be a live real time location, but it might help improve performance.