Re: Zip code
- From: "News" <sheldonlg.news@xxxxxxxxxxxxxxxx>
- Date: Thu, 28 Jul 2005 18:02:31 GMT
"Philip Ronan" <invalid@xxxxxxxxxxxxxxx> wrote in message
news:BF0E9D15.3572E%invalid@xxxxxxxxxxxxxxxxxx
> "News" wrote:
>
>> I have a database of zipcodes with latitude and longitude. I also have
>> the
>> method of calculating the distance between two zipcodes. What I want to
>> know is if there is an efficient algorithm for obtaining the zip codes
>> within a specified distance of the first zipcode without having to
>> retrieve
>> and calculate for every record in the database.
>>
>> Shelly
>
> Not really a PHP issue, but I'd try something like this:
>
> 1. Imagine a circle of the specified range centred on the target zip code.
>
> 2. Now imagine two (square-ish) boxes centred on the same point, whose
> sides
> correspond to lines of latitude and longitude. One box just fits inside
> this
> circle (i.e., all four corners lie exactly on the circle), and the other
> just fits around the circle (i.e., the circle is tangential to all four
> sides). You can calculate the corner coordinates of these boxes by simple
> trigonometry.
>
> 3. Build a DB query to extract all the zip codes that lie inside the
> smaller
> box. These all lie inside the specified range.
Thanks. While waiting for an answer I did a similar thing to the above on
my own. All I did was calculate the delta latitude and longitude
(radius*360/24902) and added and subtracted from the center point. That
gave the surrounding box. From there I will have not that many zipcodes. I
can test each one for distance and see if it lies within the specified
radius. That is the simplest method.
Shelly
.
- Follow-Ups:
- Re: Zip code
- From: Philip Ronan
- Re: Zip code
- References:
- Zip code
- From: News
- Re: Zip code
- From: Philip Ronan
- Zip code
- Prev by Date: Re: Client's IP address retrival
- Next by Date: Re: Zip code
- Previous by thread: Re: Zip code
- Next by thread: Re: Zip code
- Index(es):
Relevant Pages
|