如何在ColdFusion中计算Haversine公式

5

我在 ColdFusion 中找不到 Haversine 公式的任何示例(一种用于计算两个点之间距离的公式,根据它们的经纬度在球体上)。

维基百科在其他语言中有示例(http://en.wikipedia.org/wiki/Haversine_formula),但在 CF 中没有。

下面是另一位开发人员的 CF 解释,内部使用,未经完全测试。 我很想看看其他人如何在 CF 中计算这个值。 我还想了解下面的示例如何简化。

var variables.intEarthRadius = 6371;    // in km

var local.decRadius = arguments.radius / 1000;  // convert radius given in metres to kilometres

var local.latMax = arguments.latitude + degree(local.decRadius / variables.intEarthRadius);
var local.latMin = arguments.latitude - degree(local.decRadius / variables.intEarthRadius);

var local.lngMax = arguments.longitude + degree(local.decRadius / variables.intEarthRadius / cos(radian(arguments.latitude)));
var local.lngMin = arguments.longitude - degree(local.decRadius / variables.intEarthRadius / cos(radian(arguments.latitude)));





private numeric function degree(required numeric radian) hint="I convert radians to degrees." {
        return arguments.radian * 180 / pi();
    }

    private numeric function radian(required numeric degrees) hint="I convert degrees to radians."  {
        return arguments.degrees * pi() / 180;
    }
1个回答

6

嗨,Richard,谢谢,我只是试图理解一些痛苦的事情;)它看起来很完美。忘记了Java库!createObject("java","java.lang.Math")容易多了。 - Prometheus
1
永远要站在巨人的肩膀上 :-) - Richard Herbert
1
我写了那个UDF,它只是从http://www.movable-type.co.uk/scripts/latlong.html进行了快速移植。 - Henry

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接