两地经纬距离计算

<%
option explicit
const pi = 3.14159265358979323846
function GetDistance(Lat1, Long1, Lat2, Long2) '方法一
dim x
x
= (sin(DegToRads(Lat1)) * sin(DegToRads(Lat2)) + cos(DegToRads(Lat1)) * _
cos(DegToRads(Lat2)) * cos(abs((DegToRads(long2))-(DegToRads(long1)))))
x
= atn((sqr(1-x^2))/x)
GetDistance
= 1.852 * 60.0 * ((x/pi)*180)
end function
function DegToRads(Deg)
DegToRads
= cdbl(Deg * pi / 180)
end function
response.write GetDistance(
32.9697, -96.80322, 32.9697, -96.80322) & " Km<br>"
'response.End

Dim x1,y1,x2,y2 ‘方法二
x1
=32.9697
y1
=-96.8032

x2
=29.4678
y2
=-98.53506

Const EARTH_RADIUS = 6378.137
'Const Pi = 3.1415926535898

Function rad(d)
rad
= d * Pi / 180
End Function

Function GetDistance(lat1, lng1, lat2, lng2)
Dim radlat1, radlat2
Dim a, b, s, Temp
radlat1
= rad(lat1)
radlat2
= rad(lat2)
a
= radlat1 - radlat2
b
= rad(lng1) - rad(lng2)
Temp
= Sqr(Sin(a / 2) ^ 2 + Cos(radlat1) * Cos(radlat2) * Sin(b / 2) ^ 2)
s
= 2 * Atn(Temp / Sqr(-Temp * Temp + 1))
s
= s * EARTH_RADIUS
GetDistance
= s
End Function
response.write GetDistance(x1,y1,x2,y2)
%
>

posted on 2011-01-24 18:13  小宝哥哥  阅读(274)  评论(0编辑  收藏  举报

导航

Tasup