I do (using MySQL):
where = '( 6378.137 * acos( cos( radians(%s) ) * cos( radians( 
`events_locations`.`latitude` ) ) * cos( radians( 
`events_locations`.`longitude` ) - radians(%s) ) + sin( radians(%s) ) * sin( 
radians( `events_locations`.`latitude` ) ) ) ) < %s' % (lat, lng, lat, dist)
basic = basic.exclude(location__latitude=0).extra(where=[where])

The exclude was needed for some select_related stuff I do. You may can leave it 
out...

>reply to message:
>date: 11.08.2011 17:09:09
>from: "Thomas Weholt" <thomas.weh...@gmail.com>
>to: django-users@googlegroups.com
>subject: [<django-users.googlegroups.com>] "Great circle" using the django ORM?
>
>I got a model with longitude and latitude and want to be able to find
>other objects nearby a selected object. Can this be done using the
>django orm? What is the best approach to do this in a django project?
>
>I found a answer on Stackoverflow, but doesn't work with sqlite. Doing
>it in SQL is ok and probably the best solution performance wise, but
>if it has to be done in python I'll do that too.
>
>Ref question on stackoverflow:
>http://stackoverflow.com/questions/4610717/django-determining-if-geographic-coordinates-are-inside-of-an-circle
>
>-- 
>Mvh/Best regards,
>Thomas Weholt
>http://www.weholt.org
>
>-- 
>You received this message because you are subscribed to the Google Groups 
>"Django users" group.
>To post to this group, send email to django-users@googlegroups.com.
>To unsubscribe from this group, send email to 
>django-users+unsubscr...@googlegroups.com.
>For more options, visit this group at 
>http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to