我正在努力使用户所在位置的10英里范围内的所有事件。我的模型是这个样子:在一个点的x英里内找到物体
class User(models.Model):
location = models.PointField()
...
class Event(models.Model):
location = models.PointField()
...
在我的测试中,当我检查用户和事件之间的距离,我得到的值11.5122663513
:
from geopy.distance import vincenty
print vincenty(request.user.location, event.location).miles # 11.5122663513
然而,当我查询所有10英里用户的位置的范围内活动时,返回的事件:
Event.objects.filter(location__distance_lte=(request.user.location, D(mi=10))).count() # 1
只有当我把半径不到4英里,并过滤生效:
Event.objects.filter(location__distance_lte=(request.user.location, D(mi=3))).count() # 0
我跟着docs' example几乎到了,所以我不认为我的查询是问题。
什么可能导致这种差异?
我结束了缓冲区出点到一个圆圈选项。对于任何与该选项一起使用的人,请务必将[将半径转换为度数](http://stackoverflow.com/questions/5217348/how-do-i-convert-kilometres-to-degrees-in-geodjango- GEOS)。 – yndolok