开发者

How to workout the Haversine formula in ColdFusion

I cannot find any e开发者_如何学Pythonxamples in CF of the Haversine formula (a formula for working out distances between two points on a sphere from their longitudes and latitudes).

Wikipeda has examples in other languages (http://en.wikipedia.org/wiki/Haversine_formula) but none in CF.

An interpretation in CF is below by another developer, internal, and not fully tested. I am interested to see how others have calculated this in CF. I would also be interested to get opinions on the example below to how it can be simplified.

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;
    }


Have you looked at this...

http://cflib.org/udf/getHaversineDistance

(New URL since CFLib.org switched to static site generator)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜