在传统的ASP 2纬度/长点之间的距离

编程入门 行业动态 更新时间:2024-10-27 13:25:00
本文介绍了在传统的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纬度/长点之间的距离

本文发布于:2023-10-27 22:33:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534745.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:纬度   距离   传统   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!