2

I have a list of locations in my database stored as lng and lat. The django views is returning the longitude and latitude and latitude of the user location.I would like to return all the locations in the database within 10km of a users location. What would be the best way to do this?

def feed(request):
    latitude = request.session['lat']
    longitude = request.session['lng']
    radius = 20000
    radius = float(radius) / 1000.0 # Distance radius convert m to km
    lat = float(latitude) # Central point latitude
    lng = float(longitude) # Central point longitude

    return render(request,'main/feed.html')
Opp
  • 520
  • 1
  • 8
  • 21
  • 2
    If all your objects are already stored in your database, you won't need neither Google services nor geopy. GeoDjango has support for distance lookups, see https://stackoverflow.com/a/35896358 – KostyaEsmukov Aug 02 '19 at 05:41

0 Answers0