经典 ASP 中两个纬度/经度点之间的距离

发布于 2024-10-14 21:27:41 字数 211 浏览 9 评论 0原文

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

我发现了大量使用半正矢方程的代码示例,但在 ASP 中却没有(ASP 缺少 ACos 函数,并且没有内置 pi!我最终得到了一些代码工作,但经过仔细测试证明它是有缺陷的。我对球面几何的理解还不够好,所以有人可以说他们以前在 ASP 中做过这个吗?谢谢。

I have two pairs of latitude/longitude, and want to find the distance between them. I am stuck with using Classic ASP on this particular website.

I found plenty of code examples using the Haversine equation, but not in ASP (which lacks the ACos function, and doesn't have pi built in! I eventually got some code working, but after careful testing it proved to be flawed. My understanding of spherical geometry isn't good enough, so please can anyone say if they have done this in ASP before?! Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮惑 2024-10-21 21:27:41

哦亲爱的。我简直就是个白痴,在我进入三角学之前,没能发现一些将我的纬度/经度设置为整数的代码。我觉得很愚蠢......

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

'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

Oh dear. I have just been a complete idiot, and failed to spot a little bit of code that was setting my lat/long to integers before I even got into the trigonometry. I feel very stupid....

At least it means that my code is correct, so I'll post it here in case it helps someone else:

'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
旧时模样 2024-10-21 21:27:41

该代码源更完整:距离可以以英里、公里或海里为单位。
http://www.geodatasource.com/developers/asp

This code source is more complete : distance can be in miles, or kilometers, or nautical miles..
http://www.geodatasource.com/developers/asp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文