This demo program will calculate the distance between two points on Earth, using the latitude and longitude positions.
The main calculation routine is the following code;
This calculation returns the distance between two points in miles. If you would prefer for it to return kilometers as a default, then change the 3959 number to 6371. These two numbers are the radius of the Earth. ( 3,959 miles / 6,371 kM)
This routine can return a highly accurate value, less than a tenth of an inch. One way to test this out is to use google earth to find a football stadium that has a very high resolution image of it, so that you can easily measure the distance from one end zone to the other. I used this on the Liberty Bowl stadium in memphis, and consistently get 300.25 feet. Although the typical application for this is to get the distance between zipcodes or cities, its fun to go through Egypt and measure the distance of the sides of a pyramid.
If you want to use Google Earth to try it out, remember to set Google Earths latitude and longitude display to decimal. ( click tools, then options, then set the lat/lon section to decimal latitude)
The demo program checks the distance value, and if it is less than one mile, converts the value into feet.
The default start up positions are for New York City and Los Angeles.
Program - Distance
Display File - DistanceD
The main calculation routine is the following code;
PHP Code:
distance =
Math_ArcCosine(
Math_Sine( Math_DegreesToRadians( Latitude1 )) *
Math_Sine( Math_DegreesToRadians( Latitude2 )) +
Math_CoSine( Math_DegreesToRadians( Latitude1 )) *
Math_CoSine( Math_DegreesToRadians( Latitude2 )) *
Math_CoSine( Math_DegreesToRadians( Longitude1 - Longitude2 ))) *
3959;
This routine can return a highly accurate value, less than a tenth of an inch. One way to test this out is to use google earth to find a football stadium that has a very high resolution image of it, so that you can easily measure the distance from one end zone to the other. I used this on the Liberty Bowl stadium in memphis, and consistently get 300.25 feet. Although the typical application for this is to get the distance between zipcodes or cities, its fun to go through Egypt and measure the distance of the sides of a pyramid.
If you want to use Google Earth to try it out, remember to set Google Earths latitude and longitude display to decimal. ( click tools, then options, then set the lat/lon section to decimal latitude)
The demo program checks the distance value, and if it is less than one mile, converts the value into feet.
The default start up positions are for New York City and Los Angeles.
Program - Distance
Code:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* D i s t a n c e D e m o P r o g r a m
*
* @copyrite 1997, 2009 Michael Catalani
* ProvatoSys www.ProvatoSys.com
* mcatalani@aol.com
* 901.581.8791
*
* Get the distance in miles (or feet if less than one mile) for two
* latitude / longitude coordinates.
*
*
* Note: Latitude and Longitude coordiantes are in decimal form. You
* can use Google Earth to get the decimal coordinates for any
* location. To force Google Earth to display decimal lat / long,
* click the tools tab, then the options tab, then set the "show
* lat/lon" section to "decimal degrees."
*
* By using the floating point data type, a highly accurate
* distance calculation can be performed, to less than 1/10 of
* an inch.
*
* To test out the accuracy, use google earth to locate a football
* stadium that has a high resolution. Click the inside corners
* of the endzone line on the same side of the field, and key in
* latitudes and longitudes. You should get a value very close to
* 300 feet if the image resolution was really good, you are
* accurately positioning the pointer in google earth, and the
* guy who lined the football field was not drunk.
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
h dftactgrp(*no)
fDistanceD cf e workstn
* Program Variables
d latitude1 s 8f
d longitude1 s 8f
d latitude2 s 8f
d longitude2 s 8f
d TotalMiles s 7p 2
d TotalFeet s 7p 2
d Miles s 8f
* Constants
d pi c 3.14159265358979323846
* ProtoTypes
d Distance_PointToPoint...
d pr 8f
d Latitude1 8f const
d Longitude1 8f const
d Latitude2 8f const
d Longitude2 8f const
d Math_ArcCosine pr 8f Extproc( 'acos' )
d VariableX 8f value
d Math_Cosine pr 8f Extproc( 'cos' )
d VariableX 8f value
d Math_Sine pr 8f Extproc( 'sin' )
d VariableX 8f value
d Math_DegreesToRadians...
d pr 8f
d AngleDegrees 8f const
/free
// Set the default coordinates for New York and Los Angeles
dsplat1 = 40.7167;
dsplon1 = -74.0167;
dsplat2 = 34.05;
dsplon2 = -118.233;
dow *in03 = *off;
exfmt screen01;
if *in03 = *on;
*inlr = *on;
return;
endif;
Latitude1= dsplat1;
Longitude1= dsplon1;
Latitude2= dsplat2;
Longitude2= dsplon2;
Miles = distance_PointToPoint( Latitude1
: Longitude1
: Latitude2
: Longitude2 );
if Miles >= 1;
TotalMiles = Miles;
Distance = %editc( TotalMiles : '1' ) + ' Miles';
else;
TotalFeet = Miles * 5280;
Distance = %editc( ( TotalFeet ) : '1' ) + ' Feet';
endif;
enddo;
/end-free
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* D i s t a n c e _ P o i n t T o P o i n t
*
* Finds The Distance Between Two Latitude and Longitude Points
*
* Input Field - Latitude 1 ( floating point )
* Longitude 1 ( floating point )
* Latitude 2 ( floating point )
* Longitude 2 ( floating point )
* Returns - Distance in Miles ( floating point )
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
p Distance_PointToPoint...
p b
d Distance_PointToPoint...
d pi 8f
d Latitude1 8f const
d Longitude1 8f const
d Latitude2 8f const
d Longitude2 8f const
d Distance s 8f
/free
distance =
Math_ArcCosine(
Math_Sine( Math_DegreesToRadians( Latitude1 )) *
Math_Sine( Math_DegreesToRadians( Latitude2 )) +
Math_CoSine( Math_DegreesToRadians( Latitude1 )) *
Math_CoSine( Math_DegreesToRadians( Latitude2 )) *
Math_CoSine( Math_DegreesToRadians( Longitude1 - Longitude2 ))) *
3959;
Return Distance;
/end-free
p e
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* M a t h _ D e g r e e s T o R a d i a n s
*
* Convert Degrees to Radians
*
* Input Field - Degrees ( floating point )
* Returns - Radians ( floating point )
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
p Math_DegreesToRadians...
p b
d Math_DegreesToRadians...
d pi 8f
d AngleDegrees 8f const
d Radians s 8f
/free
Radians = pi * AngleDegrees / 180;
Return Radians;
/end-free
p e
Code:
A*%%TS SD 20090324 100030 QPGMR REL-V6R1M0 5761-WDS
A*%%EC
A DSPSIZ(24 80 *DS3)
A CF03(03)
A R SCREEN01
A*%%TS SD 20090324 100030 QPGMR REL-V6R1M0 5761-WDS
A 1 2DATE
A EDTCDE(Y)
A COLOR(PNK)
A 2 2TIME
A COLOR(PNK)
A 1 70USER
A COLOR(PNK)
A 7 3'Longitude 1..............:'
A COLOR(BLU)
A 6 3'Latitude 1..............:'
A COLOR(BLU)
A 23 3'F3-Exit'
A COLOR(WHT)
A 8 3'Latitude 2..............:'
A COLOR(BLU)
A 9 3'Longitude 2..............:'
A COLOR(BLU)
A 11 3'Distance ................:'
A COLOR(BLU)
A DSPLAT1 15Y12B 6 30COLOR(WHT)
A EDTCDE(M)
A DSPLON1 15Y12B 7 30COLOR(WHT)
A EDTCDE(M)
A DSPLAT2 15Y12B 8 30COLOR(WHT)
A EDTCDE(M)
A DSPLON2 15Y12B 9 30COLOR(WHT)
A EDTCDE(M)
A DISTANCE 50A O 11 30COLOR(PNK)
A 1 13'Calculate Distance Between Two Lat-
A itudes / Longitudes'
A COLOR(BLU)



Nice ! Now add hotlink and we're gdone !

) all fine now ---
Comment