FUNCTION HAVERSINE !--------------------------------------------------------------- !*** Haversine Formula - Calculate distances by LAT/LONG ! !*** LAT/LON of the two locations and Unit of measure are GLOBAL !*** as they are defined in the main logic of the program, so they !*** available for use in the Function. !*** Usage: X=HAVERSINE Radius=6378.137 Lat1=(Lat1*MATH.PI/180) Lon1=(Lon1*MATH.PI/180) Lat2=(Lat2*MATH.PI/180) Lon2=(Lon2*MATH.PI/180) DLon=Lon1-Lon2 ANSWER=ACOS(SIN(Lat1)*SIN(Lat2)+COS(Lat1)*COS(Lat2)*COS(DLon))*Radius DISTANCE="kilometers" SELECT CASE UNIT CASE "M" HAVERSINE=ANSWER*0.621371192 Distance="miles" CASE "N" HAVERSINE=ANSWER*0.539956803 Distance="nautical miles" END SELECT END FUNCTION