boriscy
Best algorithm to find near moving objects
I’m making an app for delivery in which a client can look for near cars for transportation, if I use a single channel the client will be listening to all available cars even the ones not near him, I thought of a solution in which each car transmits its position in a region (channel), when the car moves it should switch of region and channel, this way when a client looks for a near car it will only look for regions (channels) that are near him, can you suggest a better solution?
Most Liked
Qqwy
This is a great tip that not enough developers know about. In a more general sense: Square roots (or divisions, or other expensive computations) can often be avoided if you’re only interested in if something exceeds a certain threshold (and thus the ‘end result’ such as in this case the actual distance is not needed).
terakilobyte
What about relying on a database to handle this for you and use a geospatial query?
OvermindDL1
PostgreSQL has a fantastic geospatial engine, could easily do it via its queries.
NobbZ
Technically having the threshold as squared and comparing it, is still pythagoreas 
Mandemus
Since you are talking about cars on streets in a city, you should use Manhattan Distance. Then use a distance threshold to limit the results.
Pro tip: Square the distance threshold and compare it with the squared magnitude instead of Pythagoras. Eliminates the incredibly expensive square root.







