Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all points within certain radius in Django

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?

like image 870
Herman Schaaf Avatar asked Mar 31 '11 15:03

Herman Schaaf


1 Answers

Django has GeoDjango for this

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

like image 71
Galen Avatar answered Oct 19 '22 15:10

Galen