I am making an application which needs to be able to find people nearby, who are users of my app.
I looked at many answers of precedent similar questions, and it seems I have no choice but to keep uploading a user's current location to the server, and get nearby users' list when necessary.
Then my question is,
1. To get the nearby list, there should be some algorithm or function which calculates the distance. Then doesn't that mean I have to get all distances between my location and the rest of the app users? So the server returns certain number of users who have the least distance results. If I'm correct, wouldn't there be memory or time issues?
2. This might sound weird, but how about this.
I'll probably send latitude and longitude information or address information to the server. Can't I compare those strings with all users' address list from the first numbers or letters using string searching algorithms or something?
For example, if my last updated address is 'abcde' on the server, the algorithm will look for addresses that start with 'a', if finished searching, then look for addresses that has 'b' after 'a', in other words 'ab'.
This might not be a right solution, but I thought it might work because the address will be saved in same forms.
To find nearby users efficiently, you need a spatial index. See: Hierarchical Triangular Mesh.
You also can use one of the databases that support spatial queries.
I'll probably send latitude and longitude information or address information to the server. Can't I compare those strings with all users' address list from the first numbers or letters using string searching algorithms or something?
That won't work with latitude and longitude because that way you can only search for proximity in one dimension. For example, 30°N 30°E will appear closer to 30°N 90°E than to 31°N 30°E.
It may work with addresses, but only if they are reliably connected with coordinates (i.e. not typed in by users), and only if you don't mind that users 200 meters apart but on different sides of some administrative border will not count as close to each other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With