在Django中获取一定半径内的所有积分 [英] Get all points within certain radius in Django

查看:141
本文介绍了在Django中获取一定半径内的所有积分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Google地图应用程序,我需要创建一个查询,从每个点的lat / lng开始,我们的数据库中的所有项目都将从给定的纬度/经度中选定在一定半径范围内。在Django ORM中有没有一个有效的方法?

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?

到目前为止,我所想出的最好的方法是选择所有要落入边界的点的圈子(具有 __范围),然后在所有选定的列表上调用迭代函数,以确定它们是否真的落在圈子中。

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.

我的感觉是可能会有更有效的方式 - 你该怎么做?

My feeling is there might be a more efficient way - how would you do it?

推荐答案

Django为此

GeoDjango http://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#distance-queries\">http://docs.djangoproject.com/en/dev/ref/contrib/gis / db-api /#distance-queries

http://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#distance-queries

这篇关于在Django中获取一定半径内的所有积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆