How to "Find store locations near you" in VB?
Question posted by: 321ConTact
(Guest)
on
July 17th, 2005 09:45 PM
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).
Thanks in advance for the wisdom.
J
4
Answers Posted
"321ConTact" <contactme@sNpOvSiPsAiMonREMOVECAPS.com> wrote in message
news:MYa3c.192266$B81.2497709@twister.tampabay.rr. com...[color=blue]
> 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[/color]
has[color=blue]
> something to do with the sine/cosine, but the "signs" aren't clear enough[/color]
to[color=blue]
> me (neither are the wonders).
>[/color]
There is no formula for this. The US postal service does not assign zip
codes by longitude / latitude and distance can only be measured between two
valid addresses but not zip codes.
If not obvious, I live on the boundary of two zipcodes. My two door away
neighbor is in a different zip code.
Thus spake "Raoul Watson" <WatsonR@IntelligenCIA.com>:
[color=blue]
> "321ConTact" <contactme@sNpOvSiPsAiMonREMOVECAPS.com> wrote in message
> news:MYa3c.192266$B81.2497709@twister.tampabay.rr. com...[color=green]
>> 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[/color]
> has[color=green]
>> something to do with the sine/cosine, but the "signs" aren't clear
>> enough[/color]
> to[color=green]
>> me (neither are the wonders).
>>[/color]
>
> There is no formula for this. The US postal service does not assign
> zip codes by longitude / latitude and distance can only be measured
> between two valid addresses but not zip codes.
>
> If not obvious, I live on the boundary of two zipcodes. My two door
> away neighbor is in a different zip code.
>
>
>[/color]
True, but at the "heart" of each ZIP code is a post office, which certainly
does have a longitude and latitude; you can use the post office as a proxy
for the entire ZIP code, bearing in mind that Los Angeles ZIP codes are
tiny but Wyoming ZIP codes are huge...
All that being said, I'm afraid my trig skillz aren't up to the OP's
original question. Sorry.
> I have to find zipcodes within a given mileage range (25, 50, etc). I know[color=blue]
> 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).[/color]
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)
Quote:
Originally Posted by 321ConTact
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).
Thanks in advance for the wisdom.
J
Check this pdf link from ZipCodeWorld:
http://www.zipcodeworld.com/docs/distance.pdf.
It shows code examples for various languages and scripts. Can visit the zipcodeworld.com site for dot net controls etc. :) Hope this helps.
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 196,828 network members.
Top Community Contributors
|