Efficient way to execute a Firebase request?

My JSON object:

"userLocation" : {
   "10154053432889835" : { //UNIQUE USER ID
     "latitude" : "27.7002088506885",
     "longitude" : "85.3408864275271"
   },
   "10154053432889879" : {
     "latitude" : "27.7002088506999",
     "longitude" : "85.3408864275271"
   },
   "10154053432889456" : {
     "latitude" : "27.7002088504585",
     "longitude" : "85.3408864275271"
   }
}

This is a location location for different users of my application.

Requirements:

I want to send a message to all users who are at a certain distance from the user's current location.

For example: If the distance of user1 is 10 km from the location of user2. Then user1 or user2 can communicate with each other.

Problem:

I can download the location of all users from the userLocation node and compare with the user currentLocation, and then a message to each user if they meet the distance criteria.

This solution is not practical for a larger dataset when they say that millions of users.

Question

- userLocation node, , ?

+4

All Articles