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;
}
Have you looked at this...
http://cflib.org/udf/getHaversineDistance
(New URL since CFLib.org switched to static site generator)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With