I had to do that once it was challenging but turned out to be quite simple.
Use the Pythagorean theorem, a^2 + b^2 = c^2.
It is easy to calculate linear distance along the lines of latitude and
longitude. 1degree = so many feet, I don't know the specific numbers.
So imagine the distance you want to find, the direct line between two
zip-code centers, as the hypotenuse of a right triangle, "c". now imagine
the other lines of the triangle, squaring off at a right angle.
point A is at (G1,T1)
point B is at (G2,T2)
point C (the right angle) is at (G1,T2) (or at G2,T1 it doesn't matter)
So the length of side a (point A to point C) is the linear latitude distance
of (T2-T1). No trig involved just straight conversion degrees to feet or
meters or whatever.
The length of side b (point B to point C) is the linear longitude distance
of (G2-G1). No trig involved just straight conversion degrees to feet or
meters or whatever.
So then the length of side c, (point A to point B, our ultimate goal!) is
the square root of (a^2 + b^2).
now this is just an estimate since : (1) this is Euclidian geometry but the
geometry on a spherical surface is not Euclidian, and (2) the length of a
degree of longitude is different depending on your latitude. (1) can be
ignored for distances as small as it appears you are using. (2) can be
mitigated by looking up the correct value for your latitude and using that
in your calculations. Again at intra-state scales a single average value
will be close enough. You will have much larger error from the distance
between customers' real lat & long at their address and the zip-code center
lat & long you are using. In geographically big zip codes as you get in
rural areas addresses near the edges of a zip code might actually be closer
to the center of a neighboring zip-code. We went to zip+4 center points for
this reason... and whenever a service rep made a call he took a GPS reading
at the receiver and if that was present it was used.
-----Original Message-----
From: Leo Scott [mailto:leoscott@c...]
Sent: Friday, July 19, 2002 12:36 PM
To: Access
Subject: [access] RE: Distance Algorithm
Thanks, but I needed the algorithm. I have 80 points of service based on 5
digit zip codes and 40,000 customers, with zip codes. I have zip codes with
Lat & Long in a table. I have to calculate the crow flies shortest distance
to each point of service for each customer. I'm just going to turn a
machine loose on it and let it build a table.
|-----Original Message-----
|From: PStreeter@C...
|[mailto:PStreeter@C...]
|Sent: Friday, July 19, 2002 8:09 AM
|To: Access
|Subject: [access] RE: Distance Algorithm
|
|
|I didn't thinl of this when I read Leo's original message, but there
|are map packages available. Some are expensive and elaborate.
|I suspect there are some in the right range of prowess and price
|for you, Leo.
|
|Paul
|
|On Fri, 19 Jul 2002 10:34:05 +0100 "Foote, Chris" wrote:
|
|> cos D = sin A sin B + cos A cos B cos L
|>
|> Where A = latitude of location 1 in degrees
|> B = latitude of location 2 in degrees
|> L = long of location 1 _minus_ long of location 2. (If result is
|> greater than +180 deg or less than -180 deg, add or subtract 360 deg
|> to give
|> a result between -180 & +180 deg)
|> D = distance between location 1 and location 2 in degrees of
|> arc (each degree of arc equals 60 nautical miles)
|
|>
|> -----Original Message-----
|> From: Leo Scott [mailto:leoscott@c...]
|
|> I am looking for a formula or algorithm to calculate the distance between
|> two points given their lattitude and longitude. Since the points will be
|> fairly close curvature of the earth is not significant. Can anyone
|> point me in the right direction to find this?
|
|
|