Re: Zip code




"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


.



Relevant Pages

  • Re: decimal longitude and latitude problem
    ... distance from a specific decimal longitude and latitude. ... you can just use a variation of Bresenham's circle algorithm to see ... You would need to adjust for the way the distance of a degree of longitude ...
    (sci.math)
  • Re: Zip code
    ... > I have a database of zipcodes with latitude and longitude. ... > method of calculating the distance between two zipcodes. ... Indexing latitude and longitude might help. ...
    (comp.lang.php)
  • Re: Zip code
    ... >I have a database of zipcodes with latitude and longitude. ...
    (comp.lang.php)
  • Re: Zip code
    ... >>I have a database of zipcodes with latitude and longitude. ... >>method of calculating the distance between two zipcodes. ... have you looked at a zip code map for Manhattan? ...
    (comp.lang.php)
  • Zip code
    ... I have a database of zipcodes with latitude and longitude. ... method of calculating the distance between two zipcodes. ...
    (comp.lang.php)