Anda di halaman 1dari 2

Print Article

Seite 1 von 2

Calculate the Distance Between Two Points

Doug Dodge

Have you ever needed to calculate the distance between two points on the globe? This function will take two points -- described in terms of longitude and latitude -- and return the distance between them in miles.
Calculating the distance between two points on the globe isn't as simple as you might first think. Before I discuss why, let me refresh your memory about longitude and latitude. Lines of latitude circle the globe. The equator, for example, is a line of latitude. A degree of latitude is the distance between two consecutive lines of latitude. Since two lines of latitude are parallel, the distance between them is always the same. Thus, a degree of latitude measured near the North Pole (such as between 88 degrees and 89 degrees) is the same as near the Equator (such as between 1 degree and 2 degrees.) A degree of latitude is always about 69 miles. On the other hand, lines of longitude run from one pole to the other. Two lines of longitude intersect at both poles -- the distance between them is 0 -- and are furthest apart at the equator, where the distance is approximately 69 miles. (The circumference of the earth is approximately 25,000 miles, and there are 360 degrees of longitude: 25,000/360 = 69.44 miles.) For example, a degree of longitude (running across the globe) in Houston, Texas, or Perth, Australia (30 degrees) is approximately equal to 59 miles, while a degree of longitude in Montreal or Venice (45 degrees latitude) is 48 miles, and in Stockholm or Anchorage, it's 34 miles. As a result, you can't simply calculate the distance between two points by calculating the number of degrees between them and then multiplying the result by a number of miles per degree. The number of miles per degree of longitude varies depending on where, latitudinally, it is. The following equation, provided by CD Light in Sandy, Utah, takes these factors into account: nDistance = ; 3958.7500 * ; ACOS(SIN(nLat1/nDegrees) * ; SIN(nLat2/nDegrees) + ; COS(nLat1/nDegrees) * ; COS(nLat2/nDegrees) * ; COS(nLon2/nDegrees - nLon1/nDegrees)) where nDegrees = 180/PI() This formula can be incorporated into a routine that calculates the distance between two points on the globe, like so: * distance.prg PARAMETERS nLat1, nLon1, nLat2, nLon2 PRIVATE nParms, nDistance STORE pcount() TO nParms STORE -1 TO nDistance nDegrees = 180/PI() IF nParms <> 4 =MESSAGEBOX( ; "Incorrect number of parameters passed.", 16) ELSE * * The following formula was adapted from the * information provided by: * * CD Light * 8861 Silverstone Way * Sandy, Utah 84093-1679 * * (801) 943-0162 * (800) 571-3914 * sales@zipinfo.com *