RDMLX code for determining distance between 2 lat / long

Please mark posts as being for RPG or RDMLX (LANSA) developers.
To subscribe by email, display this forum, scroll to the end and select ‘Subscribe Forum’.
Post Reply
dhnaigles
Posts: 28
Joined: Tue May 08, 2012 12:13 am

RDMLX code for determining distance between 2 lat / long

Post by dhnaigles » Thu Jun 14, 2012 11:33 pm

If you want to calculate the distance between 2 lat/long points in degrees, here is the code in RDMLX:

Mthroutine Name(GetDistance)
Define_Map For(*INPUT) Class(#STD_FLOAT) Name(#FromLat)
Define_Map For(*INPUT) Class(#STD_FLOAT) Name(#FromLng)
Define_Map For(*INPUT) Class(#STD_FLOAT) Name(#ToLat)
Define_Map For(*INPUT) Class(#STD_FLOAT) Name(#ToLng)
Define_Map For(*RESULT) Class(#std_float) Name(#Distance)
Define_Com Class(#STD_FLOAT) Name(#degreetorad)
Define Field(#dltlng) Type(*FLOAT)
* set value of degree to radian conversion
#degreetorad := 3.14159265358979323846264338327950288419716939937510 / 180
* convert our degress to radians
#FromLat := (90 - #FromLat) * #degreetorad
#ToLat := (90 - #ToLat) * #degreetorad
#FromLng := #FromLng * #degreetorad
#ToLng := #ToLng * #degreetorad
#dltlng := #ToLng - #FromLng
#Distance := (#FromLat.sine * #ToLat.Sine * #dltlng.Cosine) + (#FromLat.Cosine * #ToLat.Cosine)
* 3960 is for miles, use 6371 for kilometers
#Distance := #Distance.ArcCosine * 3960
#Distance *= 3960

Endroutine
Regards,

David

stevec
Posts: 133
Joined: Thu Aug 23, 2012 6:45 am

Re: RDMLX code for determining distance between 2 lat / long

Post by stevec » Fri Jul 15, 2016 2:40 am

Is this code supposed to produce distance as miles as coded here?

I get 58982 miles using this code which I know is way off, but if I comment out the last line of code I get 519 which is close.

This site looks right
http://andrew.hedges.name/experiments/haversine/
First location (default: 1600 Pennsylvania Ave NW, Washington, DC)
Latitude:
41.6411770
Longitude:
-93.7770000

Expressed in decimal degrees

Second location (default: 1922 F St NW, Washington, DC)
Latitude:
43.3020161
Longitude:
-103.7312365

Expressed in decimal degrees

Calculate Clear Form

Results

520.075
miles

Post Reply