PHPBuilder - Haversine Formula (dist between two lat/long pairs)

Haversine Formula (dist between two lat/long pairs)

by: Eden Li
|
August 16, 2000

Version: 1.0

Type: Function

Category: Algorithms

Description: Determines the distance in miles between two latitude/longitude pairs (in degrees) with a slightly modified Haversine formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159). See http://earth.uni-muenster.de/~eicksch/GMT-Help/msg00147.html for more info. It was modified for speed.

```# Where:
#  \$l1 ==> latitude1
#  \$o1 ==> longitude1
#  \$l2 ==> latitude2
#  \$o2 ==> longitude2
function haversine (\$l1, \$o1, \$l2, \$o2)
{
\$l1 = deg2rad (\$l1);
\$sinl1 = sin (\$l1);
\$l2 = deg2rad (\$l2);
\$o1 = deg2rad (\$o1);
\$o2 = deg2rad (\$o2);

return (7926 - 26 * \$sinl1) * asin (min (1, 0.707106781186548 * sqrt ((1 - (sin (\$l2) * \$sinl1) - cos (\$l1) * cos (\$l2) * cos (\$o2 - \$o1)))));
}```

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Eden Li

Comment:

Comment:

(Maximum characters: 1200). You have characters left.