Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to workout the Haversine formula in ColdFusion

I cannot find any examples 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;
    }
like image 480
Prometheus Avatar asked Jul 11 '11 09:07

Prometheus


1 Answers

Have you looked at this...

http://cflib.org/udf/getHaversineDistance

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

like image 194
Richard Herbert Avatar answered Nov 01 '22 15:11

Richard Herbert