Asp classic 经典ASP中两个横向/纵向点之间的距离

Asp classic 经典ASP中两个横向/纵向点之间的距离,asp-classic,computational-geometry,latitude-longitude,Asp Classic,Computational Geometry,Latitude Longitude,我有两对经纬度,想找出它们之间的距离。我坚持在这个特定的网站上使用经典的ASP 我发现了大量使用哈弗森方程的代码示例,但在ASP(它没有ACos功能,也没有pi内置!我最终得到了一些代码,但经过仔细测试,它被证明是有缺陷的。我对球面几何的理解还不够好,所以谁能说他们以前是否在ASP中做过这件事?!谢谢。哦,天哪。我刚刚是一个完整的idiot,在我进入三角学之前,没有发现一点代码将我的lat/long设置为整数。我觉得自己很愚蠢 至少这意味着我的代码是正确的,所以我将在这里发布它,以防它对其他人有

我有两对经纬度,想找出它们之间的距离。我坚持在这个特定的网站上使用经典的ASP


我发现了大量使用哈弗森方程的代码示例,但在ASP(它没有
ACos
功能,也没有
pi
内置!我最终得到了一些代码,但经过仔细测试,它被证明是有缺陷的。我对球面几何的理解还不够好,所以谁能说他们以前是否在ASP中做过这件事?!谢谢。

哦,天哪。我刚刚是一个完整的idiot,在我进入三角学之前,没有发现一点代码将我的lat/long设置为整数。我觉得自己很愚蠢

至少这意味着我的代码是正确的,所以我将在这里发布它,以防它对其他人有帮助:

'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

哦,天哪。我只是一个十足的白痴,在我进入三角学之前,没有发现一点将我的lat/long设置为整数的代码。我觉得自己很愚蠢

至少这意味着我的代码是正确的,所以我将在这里发布它,以防它对其他人有帮助:

'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

此源代码更完整:距离可以是英里、公里或海里。。

此源代码更完整:距离可以是英里、公里或海里。。

回答了我自己的问题。啊!回答了我自己的问题。啊!