Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6477 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I am trying to implement this Formula into my solution and am getting an invalid result.

It is a Haversine Function and below is what I created as a custom Function with:

Can any one figure out what I am doing wrong here?

//Computes the Distance between two points on Earth's Surface

// input:

// lat1,long1,lat2,long2 = lat and long of two points, in DECIMAL DEGREES

// units = "miles" or "km"

// output: Distance between the two points in miles or kilometers

Let ([

D = Case( Trim(Lower(Left(units;1))) = "m"; 3958.75; 6367.45 );

// Diameter of Earth in miles or km

lat1R = Radians(lat1);

lat2R = Radians(lat2);

long1R = Radians(long1);

long2R = Radians(long2);

dlat = lat2R - lat1R;

dlong = long2R - long1R;

a = (Sin(dlat/2))^2 + Cos(lat1R) * Cos(lat2R) * (Sin(dlong/2))^2;

c = 2 * Atan(Sqrt(a)/Sqrt(1-a));

result = D * c

];

result

)

My fields are;

MP_HOME_LATTITUDE

MP_HOME_LONGITUDE

VF_GPS_LATTITUDE

VF_GPS_LONGITUDE

My result Field with Calculation is:

MILES = Haversine ( MILES ;MP_HOME_LATTITUDE; VF_GPS_LATTITUDE; MP_HOMELONGITUDE;

VF_GPS_LONGITUDE )

Does any one know what I am missing here to get a valid result?

My Calc settings are - Do not Evaluate if Referenced Fields are Empty (CHECKED) and

Do not replace existing value for field (UNCHECKED) and

Always Validate is set to on.

Thanks for any help on this!

Posted

I don't see anything obvious - except perhaps the order of the input parameters does not match the order as defined in the function?

Why don't you use a calculation field instead of auto-enter? And what is there to validate?

Posted

Comment, I sent a Reply, but do not see it, so will try again.

Did you get this to work? I have tried everything and this is not a complex function. It has to be something simple that I am doing wrong. I changed the Validation and what do you mean by Calculation Field?

Thanks

Posted

OK. You have a field named 'miles'. And you are calling your function like this:

Haversine ( Latitude1 ; Longitude1 ; Latitude2 ; Longitude2; miles;)


Which means that the 'units' parameter is the value of the field 'miles'. Therefore you are getting the correct result, only in kilometers.





Either call the function like this:




Haversine ( Latitude1 ; Longitude1 ; Latitude2 ; Longitude2; "miles" )




or define a field for units, then:




Haversine ( Latitude1 ; Longitude1 ; Latitude2 ; Longitude2; Units )

Posted

I tried posting this earlier, but I was having problems with the website. Comment pretty much summed up what i was ging to tell you to do. I took it a different route, by choosing to send R (radius of the earth value in either miles or km) as part of the CF parameter. Its just made more sense to me but in the end its just personal preference.

Haversine_Function.zip

Posted

Ok. Thanks guys. I figured out what I was doing. I was trying to perform the calc on a related field from another table and when I did a cut and paste, it worked fine.

Only thing is that I did a mapquest and google map on two different addresses that both showed as being 130 miles a part. When I looked up the Lat and Long from :P

http://www.gpsvisualizer.com/geocode

It gave me a 166.68 miles. Now I wonder who is right and who is wrong. But not your guys problem, just an observation.

Thanks again for your help!

This topic is 6477 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.