<%
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
'::: These functions may come in handy for processes that need to find :::
'::: distances between two points on the planet. It is derived from :::
'::: spherical trigonometry. Although the earth is actually an oblate :::
'::: spheroid, these methods are generally accurate for non-navigational :::
'::: purposes (e.g. e-commerce calculations for store-finders, etc.) :::
'::: Do NOT use them to plot your next trip around the world. :) :::
'::: :::
'::: :::
'::: blah blah blah blah blah blah blah blah blah blah blah blah blah blah :::
'::: blah blah blah blah blah blah blah blah blah blah blah blah blah blah :::
'::: blah blah Copyright *c* 2000, Mike Shaffer. blah blah blah :::
'::: blah blah ALL RIGHTS RESERVED WORLDWIDE blah blah blah :::
'::: blah blah Specific permission to use this routine blah blah blah :::
'::: blah blah in any way is granted by Mike Shaffer blah blah blah :::
'::: blah blah provided that these comments are included blah blah blah :::
'::: blah blah and that copyright ownership is retained. blah blah blah :::
'::: blah blah blah blah blah blah blah blah blah blah blah blah blah blah :::
'::: blah blah blah blah blah blah blah blah blah blah blah blah blah blah :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
option explicit
const pi = 3.14159265358979323846
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
'::: This routine calculates the distance between two points (given the :::
'::: latitude/longitude of those points). :::
'::: :::
'::: Definitions: :::
'::: South latitudes are negative, east longitudes are positive :::
'::: :::
'::: Passed to function: :::
'::: Lat1, Long1 = Latitude and Longitude of point 1 (in decimal degrees) :::
'::: Lat2, Long2 = Latitude and Longitude of point 2 (in decimal degrees) :::
'::: Unit = the unit you desire for results :::
'::: where: 'M' is statute miles :::
'::: 'K' is kilometers (default) :::
'::: 'N' is nautical miles :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function GetDistance(Lat1, Long1, Lat2, Long2, Unit)
dim x
' do the nasty calcs
x = (sin(DegToRads(Lat1)) * sin(DegToRads(Lat2)) + cos(DegToRads(Lat1)) * _
cos(DegToRads(Lat2)) * cos(abs((DegToRads(long2))-(DegToRads(long1)))))
' Get Acos(x)
x = atn((sqr(1-x^2))/x)
' Get distance in kilometers
GetDistance = 1.852 * 60.0 * ((x/pi)*180)
' Convert units if necessary
select case ucase(Unit)
case "M"
GetDistance = GetDistance / 1.609344
case "N"
GetDistance = GetDistance / 1.852
end select
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: This function converts decimal degrees (e.g. 79.1928376) to radians :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function DegToRads(Deg)
DegToRads = cdbl(Deg * pi / 180)
end function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: This function converts decimal degrees (e.g. 79.1928376) to degrees, :::
'::: minutes and seconds :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
sub DecimalDegToDMS(DecimalDegrees, Degs, Mins, Secs)
Dim temp
Degs = fix(DecimalDegrees)
temp = (DecimalDegrees - Degs) * 60.
Mins = fix(temp)
temp = (temp - Mins) * 60.
Secs = fix(temp)
end sub
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: Sample code for testing (may be removed) :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
dim d, m, s
response.write "Calculating the distance between Dallas (75248) and San Antonio (78201)
"
response.write GetDistance(32.9697, -96.80322, 29.46786, -98.53506, "M") & " Miles
"
response.write GetDistance(32.9697, -96.80322, 29.46786, -98.53506, "K") & " Km
"
response.write GetDistance(32.9697, -96.80322, 29.46786, -98.53506, "N") & " Nautical Miles
"
DecimalDegToDMS 32.9697, d, m, s
response.write "Dallas' decimal latitude of 32.9697 can also be shown as " & d & "° " & m & "' " & s & """"
response.write ""
response.end
%>