This is the code I am using

 

/**

* Calculates distance between Latitude/Longitude points using haversine formula.

* 

 * @param lat1    latitude of first point (Required)

* @param lon1    longitude of first point (Required)

* @param lat2    latitude of second point (Required)

* @param lon2    longitude of second point (Required)

* @param units  Units for return value. Default is miles. (Optional)

* @return Returns numeric distance between the two points. Units varies, 
default is miles. 

 * @author Henry Ho (henryho...@gmail.com) 

 * @version 0, January 8, 2013 

 */

function getDistance(lat1, lon1, lat2, lon2, units = 'miles')

{

        // earth's radius. Default is miles.

        var radius = 3959;

        if (arguments.units EQ 'kilometers' )

                 radius = 6371;

        else if (arguments.units EQ 'feet')

                 radius = 20903520;

        

        var toRad = pi() / 180;

        var dLat = (lat2-lat1) * toRad;

        var dLon = (lon2-lon1) * toRad; 

        var a = sin(dLat/2)^2 + cos(lat1 * toRad) * cos(lat2 * toRad) * 
sin(dLon/2)^2; 

        var c = 2 * createObject("java","java.lang.Math").atan2(sqr(a), 
sqr(1-a));

        

        return radius * c;

}

 

 

Its wrapped inside a cfloop as I need to validate code received into our portal 
from mobile devices against data stored in the database hence the need to look 
around the data records from the query as often there will be more than 1 
records to test against

 

 

 

 

 

NB: TrackingCentral is now a registered product & services provider for the 
National Disability Insurance Scheme, under the category of Assisted Technology

 

Regards

 

Claude Raiola
Director
TrackingCentral Pty. Ltd

Free Call 1300 255 990

 



 

 

From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On Behalf Of 
Charlie Arehart
Sent: Thursday, 26 March 2015 1:26 PM
To: cfaussie@googlegroups.com
Subject: RE: [cfaussie] Help With Dynamic Naming A CfScript Function

 

Right, but why do you need the name of the function to be dynamic? Why isn’t it 
enough that you pass in args within the loop (and declare the function outside 
of it)?

/charlie

From: cfaussie@googlegroups.com <mailto:cfaussie@googlegroups.com>  
[mailto:cfaussie@googlegroups.com] On Behalf Of rai...@ozemail.com.au 
<mailto:rai...@ozemail.com.au> 
Sent: Wednesday, March 25, 2015 11:14 PM
To: cfaussie@googlegroups.com <mailto:cfaussie@googlegroups.com> 
Subject: RE: [cfaussie] Help With Dynamic Naming A CfScript Function

 

I am calculating distance between 2 sets of lon / lat and the information is 
dynamic so I need to capture the values of the dynamic data and compare them to 
the values stored in a database table of which there may been to be several 
records tested against the values in the dynamic data 

 

Eg 1 set of co ordinate received from a device in the field data is received by 
the listener and needs to be tested against co ordinates recorded in the 
database table of which there may be several records needing to be tested 
against hence the need for the loop

 

Regards

 

Claude Raiola

 

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cfaussie+unsubscr...@googlegroups.com 
<mailto:cfaussie+unsubscr...@googlegroups.com> .
To post to this group, send email to cfaussie@googlegroups.com 
<mailto:cfaussie@googlegroups.com> .
Visit this group at http://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cfaussie+unsubscr...@googlegroups.com.
To post to this group, send email to cfaussie@googlegroups.com.
Visit this group at http://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.

Reply via email to