Circle is hard.  What you can do is create a bounding box which is
rectangular in lat/long space (if not in physical space) whose sides
are tangent to your desired distance circle.  You will search a few
more users than if you could really restrict them to the distance
circle a priori, but it will significantly cut down the number of trig
functions you execute.  (Limiting to the bounding box takes at most
four floating compares - I do it in the data base.)

The northern and southern boundaries are easy.  Getting the eastern
and western sides requires realizing that (your choice of) pole, the
center of the distance circle, and the point at which the distance
circle is tangent to a line of longitude, form a spherical right triangle,
with the tangent point being the right angle.  I found a suitable
formula in my old DRC math tables, but I'm sure that you can find
it on the web as well.

Bill


2010/7/29 Alexandre González <agonzale...@gmail.com>:
> Hi!
> I'm searching near people in my app. I'm doing it a this way:
> 37             people = Person.objects.all().exclude(user=request.user)
> 38
> 39             near_people = list()
> 40             for person in people:
> 41                 if self.is_near(me.coordinates, person.coordinates):
> near_people.append(person)
> Now, I'm getting all the the Person objects. This is a inefficient way.
> The coordinates are latitude/longitude coordinates, so I think in test the
> variation and get only latitude +/- 1 and longitude +/- 1 and after this, do
> the test exactly (the funcion is_near).
> But instead this, can I "draw" a circle and search only Person objects
> inside it?
> Thanks!
> --
> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> and/or .pptx
> http://mirblu.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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