About a year ago on a long bus ride, my friend and I brainstormed ideas for our future personal projects. My friend mentioned something about a chat app that would be regionally locked—an app where you could chat with random people near you. Something like Omegle but LOCAL. I was immediately interested.
At that time, I couldn’t even imagine what it would take to actually create something like this. But somehow, I didn’t care. I actually didn’t care even enough to research what apps already did something similar and if the project had any potential for a fanbase. I just wanted to create!
Topology choice
At first, I figured that for an app of this scale, I would need a very powerful main server or to be able to run everything serverless. I had a lot of ideas about using some variation of P2P chains or circle topology for message sending and receiving, but my knowledge of these things was severely limited. Therefore, after discovering that Oracle gives out free servers, the answer was clear.
First steps
The initial idea was to store all the messages in files named appropriately so that each file name would track back to the real world in 100 by 100 meter blocks.

LAT = Latitude LON = Longitude
As seen in the professionally drawn diagram above, the user would get information from the nearest 9 blocks ⇒ files around him and sort them by time of creation, and the message sent from the user would end up in the block ⇒ file where the user is currently standing.
And so I started coding. I decided that the backend would be in Python, as that was the language I was most comfortable with, and I couldn’t imagine learning a new language when this project was already on the bounds of my skill. After setting everything up with HTTP, I arrived at my first problem: the Earth isn’t flat!
After some testing, I figured my naive approach of taking the LAT, LON, dividing them by 360, then multiplying by the Earth’s circumference (40,000,000 m) to get the location of the user in meters wouldnt work!
\[ \text{Position}_{\text{LAT}}\, [\text{m}] = \text{LAT} \times \left( \frac{40\,000\,000}{360^\circ} \right) \] \[ \text{Position}_{\text{LON}}\, [\text{m}] = \text{LON} \times \left( \frac{40\,000\,000}{360^\circ} \right) \]It would squish my horizontal distance to other blocks to about 60% of what it should have been on the equator, meaning you wouldn’t get the full 100m range horizontally. 🙁

The solution
This was devastating at first, but after some quick napkin math, I figured out a “solution.”

Instead of calculating
\[ \text{Position}_{\text{LON}}\, [\text{m}] = \text{LON} \times \left( \frac{40\,000\,000}{360^\circ} \right) \]I could just multiply this by cos(LAT) and therefore “unsqueezing” my horizontal distance to other blocks.
\[ \text{Position}_{\text{LON}}\, [\text{m}] = \text{LON} \times \left( \frac{40\,000\,000}{360^\circ} \right) \times \cos(\text{LAT}) \]Simple on paper and much harder to implement, this solution fixed the squishing problem and my app could finally work!
After all this, I just made a live map where you can see where the current active users are and the messages that they left.
Avalable here

Future of the project
For now, this project is at least in my eyes finished, and I don’t have any further plans for development.
Leave a Reply