I am using GeopositionField in Django to store the coordinates of my user. Now I want to find a list of 20 users who are closest to current user. Can that functionality be acheaved my GeopositionField? I know that GeoDjango makes it easy to search distances, but since I am using Heroku and postgresql, I want to keep the costs down and with postgressql, installing PostGIS seems to be the only alternative.
Any suggestions?
For the distance between two points you can use Geopy.
From the documetation: Here's an example usage of distance.distance:
To implement this in a Django project. Create a normal model in models.py:
To optimize a bit you can filter user objects to get a rough estimate of nearby users first. This way you don't have to loop over all the users in the db. This rough estimate is optional. To meet all your project requirements you maybe have to write some extra logic:
Calculate the distance between your user and each user in users, sort them by distance and get the first 20.