For a Google Maps application, I need to create a query that selects all items in my database that fall within a certain radius from a given latitude/longitude, given the lat/lng of each point. Is there an efficient way to do this in the Django ORM?
对于Google地图应用程序,我需要创建一个查询,根据每个点的纬度/经度,选择数据库中距离给定纬度/经度的特定半径内的所有项目。有没有一种有效的方法在Django ORM中执行此操作?
The best way I have come up with thus far is to select all points that will fall within a bounding square of that circle (with __range
) and then call a iterative function on all the selected listings to determine whether they really fall in the circle.
到目前为止,我提出的最好的方法是选择所有将落在该圆的边界内的点(使用__range),然后在所有选定的列表上调用迭代函数,以确定它们是否真的落入了圆圈。
My feeling is there might be a more efficient way - how would you do it?
我的感觉是可能有一种更有效的方式 - 你会怎么做?
1 个解决方案
#1
8
Django has GeoDjango for this
Django为此设有GeoDjango
http://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#distance-queries
#1
8
Django has GeoDjango for this
Django为此设有GeoDjango
http://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#distance-queries