Mag*_*ith 1 latitude-longitude asp-classic computational-geometry
我有两对纬度/经度,想找到它们之间的距离。我一直坚持在这个特定网站上使用经典 ASP。
我发现了大量使用半正矢方程的代码示例,但在 ASP 中却没有(ASP 缺乏该功能ACos,并且没有pi内置功能!我最终得到了一些代码,但经过仔细测试,它被证明是有缺陷的。我对球面的理解几何还不够好,所以请谁能告诉一下他们以前是否在 ASP 中做过这个?!谢谢。
哦亲爱的。我简直就是个白痴,在我进入三角学之前,没能发现一些将我的纬度/经度设置为整数的代码。我觉得自己非常愚蠢......
至少这意味着我的代码是正确的,所以我将其发布在这里,以防对其他人有帮助:
'calculate distance in miles between two coordinates
Function DistanceBetweenPoints(iLat1, iLong1, iLat2, iLong2)
Dim iDistance
'first assume that the earth is spherical (ha ha)
iDistance = ACos( ( Sin(ToRad(iLat1)) * Sin(ToRad(iLat2)) ) + ( Cos(ToRad(iLat1)) * Cos(ToRad(iLat2)) * Cos(ToRad(iLong2) - ToRad(iLong1)) ) ) * 3959 'mean radius of earth in miles
DistanceBetweenPoints = CInt(iDistance) 'round up to lose decimal place
End Function
'ASP doesnt have these two trigonometric functions, or pi, built in (needed above)
Const PI = 3.141592653589793100 'use this value from SQL
Function ToRad(iDegrees)
ToRad = CDbl(iDegrees) * PI / 180
End Function
Function ACos(x)
If x = 1 Then
ACos = 0
ElseIf x= -1 Then
Acos = PI
Else
ACos = ATn(-x / Sqr(-x * x + 1)) + 2 * ATn(1)
End If
End Function
Run Code Online (Sandbox Code Playgroud)