How to filter a django model with latitude and longitude coordinates that fall within a certain radius

后端 未结 3 661
轮回少年
轮回少年 2021-02-06 01:39

I have the following model.

class Location(models.Model):
    name = models.CharField(max_length = 128, blank = True)
    address =models.CharField(max_length =          


        
3条回答
  •  难免孤独
    2021-02-06 02:04

    You can do range queries with filter.

    LocationsNearMe = Location.objects.filter(latitude__gte=(the minimal lat from distance()),
                                              latitude__lte=(the minimal lat from distance()),
                                              (repeat for longitude))
    

    Unfortunately, this returns results in the form of a geometric square (instead of a circle)

提交回复
热议问题