I want to integrate a public chatroom within my app however I am clueless as how to create the backend.
I use firebase for my app and the setup is simple between two users or a group of users. I create a private room based on a reference point in Firebase which allows the users in that group to access the messages.
Now lets say I am in LA, I want users to be able to chat with other users that are within a 1 mile radius from their location (lat/lng). I know its possible as there is an app that does this which can be found at https://itunes.apple.com/sg/app/popcorn-messaging/id718416705?mt=8.
Only read the following if you want to know what I've tried. It may be a bit confusing.
One way I thought about doing this is creating a chatroom throughout the world with a mile spacing. For example, start with lat:0, lng:0 and then move a mile to the right, then another mile to the right, etc. however that does more harm than good. I will have millions of chatrooms and not all used.
Second way I thought I can implement is create a chatroom if it doesn't exists within a users radius. So if I'm in LA, and there are no chatrooms, it would create one at that location and lets say if another person goes to LA because a chatroom was already created within a 1 mile location, it will load the chatroom for that user.
Any suggestions will be greatly appreciated.
If you're sure that you want it to be 1 mile by 1 mile or any type of set distance, I think the predefined chat rooms throughout the world with a mile spacing is the better option. This will be much simpler as far as adding new users and avoiding overlaps when people move locations. If you're using firebase, and you flatten your data correctly, you won't hurt yourself too much by having empty rooms.
The only reason I might not do this is if you're worried about chat rooms becoming too full or too empty. I'm not sure if that is a concern for your application, but that would certainly be a drawback of having predefined locations. Even then, you could use the predefined locations and scale back (splitting off the rooms) or scale up (merging rooms together) based on how many people are in the rooms.
Hope this helps. If you're looking for more direction, could you tell us a little more about your application?
UPDATE: I see what you're saying. After further thought, I do still think the pre-determined areas would be the best way to go. Even if you create new areas spontaneously there will still be a point where you will need to break up the rooms (draw the boundaries between rooms) and users on either side of that line, even if they are right next to each other, will be in different rooms.
If it is just based on lat/lng and a radius around those users, that could end up with odd results as well. For example, if User B is in a room with user A and C, but users A and C are too far from each other, they might see some very weird chat messages. For example, if that radius was 1 mile,
User A could be at
User B could be at
Mile 1, and
User C could be at
Mile 2. So to
User A (who can only see
User A and
User C)` the chat could look like this:
User A: Hello there! What is 2+2? User B: 4 User A: Thank you! User B: George Washington User A: What?!?!
User B (who is the only one who will see all of the messages) it could look like this:
User A: Hello there! What is 2+2? User B: 4 User A: Thank you! User C: Who was the first president of the United States? User B: George Washington User C: Thank you! User A: What?!?!
User C (who can only see
User B and
User C) it could look like this:
User B: 4 User C: Who was the first president of the United States? User B: George Washington User C: Thank you!
It seems like this could spiral out of control pretty quickly. After all of that, I think my original suggestion is still the best, but I think all of them will have challenges. Good luck!