在传统的ASP 2纬度/长点之间的距离 [英] Distance between two lat/long points in Classic ASP

查看:118
本文介绍了在传统的ASP 2纬度/长点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两条经/纬度,并想找到它们之间的距离。我坚持这个特殊的网站上使用传统的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.

我发现很多使用半正矢公式code的例子,但不是在ASP(其中缺少 ACOS 功能,并且不具有 PI 建!我终于得到了一些code工作,但经过仔细测试它被证明是有缺陷的。我球面几何学的理解不够好,所以请任何人都可以说,如果他们在ASP?!感谢这样做过。

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.

推荐答案

哦,亲爱的。我刚去过一个完整的白痴,而未能发现code这是我的设置纬度/长整型之前,我甚钻进了三角的一点点。我觉得自己很愚蠢......

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....

至少它意味着我的code是正确的,所以它可以帮助别人,我会在这里发布的情况下:

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

这篇关于在传统的ASP 2纬度/长点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆