1

I have an idea for a part of my app but I'm not sure on the best way to do it logically. So the basic idea is I was 3 people that are using the app to appear on each of their screens. So they open the app, a map view appears and 3 of their friends have appeared moving on the map in real time IF they are within a radius of say 5km.

A better way to explain this is to imagine a school, and each kid had the app open, the teacher could see where every single kid was in real time as they are all within a radius of 5km.

My first instinct was to just get each user's current location and update that users lat and long in a database. And then every 3 seconds or so, every device will get ever user from their database and display a marker of their lat and long on the map. My main problem would be if there are 10k users in a database being updated every second, it might crash and have a lot of stress on it. Also, if it only shows users within a 5km radius of each other, would the best way be to do like an SQL query? so like get all users from user table where lat is +-5km of device location and same for long That would be a square, not a radius but that's the only thing I can think of.

I'm pretty new to iOS development and I hear the best database is Firebase? I'm not sure if it's better to just use SQL though

If anyone could help me out on the logic behind this it would be greatly appreciated

Thank You :)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Slavik Ribz
  • 165
  • 12

1 Answers1

0

For this kind of query with multiple clauses, I would indeed recommend you using SQL because even though Firebase is a great backend, it doesn't allow multiple querying just yet and it would end up be more data-consuming in that specific use case.

If you decide to use Firebase though, you could still handle filtering (show only user less than 5km radius) on the client for example. But this would require you to pull ALL the users first, and then to filter them (on the client) in order to keep only the ones that are less than 5km away. This would inevitably cost you more data than needed in the end, but it's possible.

To limit the numbers of users returned, you could still do some filtering using :

yourDatabaseRef.orderBy("X").equalTo("Y")

For the other part of your question (the calculation of all the points that are within the 5km radius) you can find many answers on this interesting thread. :)