So your problem is more like a publish-subscribe messaging system is needed here like Kafka.
If I have understood your problem right, you want to have feeds of nearest cities/areas after fetching the current location of your application user. Right now, we've many tools and technologies to serve this purpose (e.g. Kafka). But this problem is Firebase specific, so that no server side coding is required. I'm not sure about giving a solution to your problem, but lets just think how the problem can be solved and then we can try to replicate the solution in a Firebase way.
We may think of a channel where the posts from each user of your application is dumped. Each post has a key identifying their location. Now let us think of each user of your application as a subscriber with some specific topic in that channel. As soon as any subscriber (i.e. an user of your application) comes, the channels feeds that subscriber with the posts they want (i.e. the posts of nearby cities).
For example, lets we have some posts in that channel having keys, NY
, Dhaka
, Khulna
, NJ
, London
, Seoul
, Sydney
etc. Now someone from Jessore
just have subscribed in your channel and the nearby cities for him is Dhaka
and Khulna
. So the subscriber has the key Dhaka, Khulna
and when the channel sees they key, it serves the posts containing location with the key Dhaka
and Khulna
.
Now how can we achieve this behaviour in Firebase? That's the challenge we're facing right at this point. So let us have a channel
node having all posts from all location (like the channel described earlier). Here's an example data structure.
channel
- post1
- content : "this city is beautiful"
- location: "Khulna"
- post2
- content : "This city is okay"
- location: "Dhaka"
- post3
- content : "London, here I come"
- location: "London"
- post4
- content : "leaving the city"
- location: "NY"
Now, you need to have a distance-mapping
among the cities, which will tell you the nearest cities when you pass your current city to that table. You need to find out your own distance mapping for the cities given. Lets say, your current city is Jessore
. Your distance mapping table should return the nearest cities (e.g. Dhaka
and Khulna
). This might be a complex one to build. But once the relation mapping is built, its merely will be needed to update. For example, the final state of your distance-maping
data will look like.
distance-mapping
- Dhaka
- Khulna
- Jessore
- Khulna
- Dhaka
- Jessore
- Jessore
- Dhaka
- Khulna
- Vegas
- NY
- NY
- Boston
- Vegas
Now when you get the current location of your user, you'll easily find the nearest cities from the distance-mapping
table in Firebase. Pass the cities to the channel
table get the posts having those specific keys.
Here's some answers regarding complex queries in Firebase. You might get help passing select query parameter from these.
Hope that helps!