# [thelist] Calculating distnace between two zip codes.

Scott Dexter sgd at ti3.com
Tue Jan 30 18:08:32 CST 2001

```> -----Original Message-----
> From: April [mailto:april at farstrider.org]
> Sent: Tuesday, January 30, 2001 4:33 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] Calculating distnace between two zip codes.
>
>
> I need to calculate the distance between two zip codes on a website.

We (ti3) used the longitude and latitude of the center of each zip code and
calculated distance based on that. Here's the equation used (long and lat
are in decimal, not degrees):

double CGeoDistCtrl::getDistance(double Latitude1, double Longitude1, double
Latitude2, double Longitude2)
{

cosine function (pi/180)
temp = 69.171;       // number of miles in one degree longitude

dist = temp * sqrt((((cos(((Latitude2 + Latitude1) / 2) * radians) *
(Longitude2 - Longitude1)) *
(cos(((Latitude2 + Latitude1) / 2) * radians) * (Longitude2
- Longitude1))) +
((Latitude2 - Latitude1) * (Latitude2 - Latitude1))));

return dist;
}

Hope this helps some--
sgd
--
work: http://www.ti3.com/
non: http://thinksafely.org/

```