I have a python program sitting in server side managing user location informations, each friend has a pair of (longtitude, latitude), given a (longtitude, latitude) point, how I can find the nearby(say within 5KM) friends efficiently?
I have 10K users online...
Thanks.
Bin
Make a dict {graticule: [users]} (a "graticule" is a block of 1 degree latitude x 1 degree longitude; so you can basically just round the values). To find nearby users, first get users from the same and adjacent graticules (since the target could be near an edge), then filter them with a basic bounding-box test (i.e. what are the minimum longitude/latitude that are possible for someone within the desired radius), then do a detailed test (if you need accuracy then you are in for some more complex math than just Pythagoras).
algorithm to find the nearby friends?