Re: "People near me" query

From: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
To: Yannick Warnier <ywarnier(at)beeznest(dot)org>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: "People near me" query
Date: 2004-03-19 11:45:58
Message-ID: 405ADD76.1090508@zara.6.isreserved.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yannick Warnier wrote:
>>Imagine an Orkut-like site. Suppose we have 'person' table of 100k
>>people. About 75% of these people fill in their location
>>(City/State/Country) information. We also have a 'city' table containing
>>list of cities with their state & country and each city's
>>latitude/longitude. Assume all people's location is registered in the
>>'city' table.
>>
>>How does one design a database to be able to process "Show me people
>>that live no farther than 250 miles from where I live" quickly? I can do
>>"Show me people that live within (A-X to A+X) latitude and (B-X to B+X)
>>longitude" though. (Where A and B is the latitude and longitude [of the
>>person], and X is some numeric value.
>
> I think the answer depends on the precision you want. Reading your post,
> it doesn't seem to me you need a lot of precision.
>
> Usually your technique could do for an approximation. If you want to be
> more precise though, you would have to use a completely different
> calculation or structure.
>
> Did you think about the fact that longitude is different in terms of
> distance if you look it from here or from the equator?

Yes, I'm aware about the [near-]spherical nature of the Earth. I *was*
afraid that I would need to store the distances between cities since
that would mean the distance table size would be (city table)**2.

I'll check PostGIS out, thanks.

--
dave

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Al Cohen 2004-03-19 12:29:11 High Reliability without High Availability?
Previous Message Yannick Warnier 2004-03-19 10:27:46 Re: "People near me" query