> I have to find zipcodes within a given mileage range (25, 50, etc). I know
it's possible to use the longitude/latitude to find this, and I have that
for the zipcodes, but does anyone have a "ready made" formula? I know it has
something to do with the sine/cosine, but the "signs" aren't clear enough to
me (neither are the wonders).
It depends on what you are trying to do. Assuming Long/Latitude creates
perfectly horizontal and vertical lines (which they do in about 25-30miles
radius), then a famous mathematician might be able to help.
Pythagoras (Greece, BC) came up with a rule we still use today.
(a^2) + (b^2) = (c^2)
If a = latitudinal distance, b = longitudinal distance, then c = distance
between the two points.
For each ZIP code, you'll have to do
a = x1 - x2
b = y1 - y2
c = Sqrt((a^2) + (b^2))
Where x1 is latitude of the "from" ZIP, x2 is lat. of the "to" ZIP,
y1 is long. of the "from" ZIP and y2 is long. of the "to" ZIP.
Alternatively, a is the difference in latitude of the two ZIPs, b is the
difference in longitude of the two ZIPs. These can be negative, as squaring them
makes them positive in any case.
Now, if c =< 25, then the distance is less than or equal to 25miles from ZIP to
ZIP.
Finally, the bummer: Where do you measure long/latitude?
You can either find the middle of the streets ((left end + right end) / 2) or
you can find some other way.
Trig doesn't come into it, unless the distance is large (such as 100miles) as
the curvature of the Earth forces us to abandon Euclidean co-ordinate systems
and think spherically, which is too difficult.
--
QuickHare
(BSc in Maths with Computer Science)
(QuickHare "at" Hotmail "dot" com)