How to return a record with the lowest distance from a point using geodjango?

后端 未结 3 1788
无人及你
无人及你 2021-02-09 17:45

I am using geodjango and have a collection of points in my database. To get a queryset of points within a certain area I use this:

queryset = Spot.objects.filter         


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 18:29

    queryset = Spot.objects.distance(origin).filter(distance__lte=distance_m)
    point = queryset.order_by('distance')[:1][0]
    

    https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoquerysets/#distance

提交回复
热议问题