× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Here you go 

** Prototype for Get_Miles                       
 ** Convert lat/long dec from/to to miles         
 D Get_Miles       PR             8s 4            
 D  Dec_lat1                      7s 4 Value      
 D  Dec_long1                     7s 4 Value      
 D  Dec_lat2                      7s 4 Value      
 D  Dec_long2                     7s 4 Value      

PGet_Miles        B                   Export

D Get_Miles       PI             8s 4

D  Dec_lat1                      7s 4 Value

D  Dec_long1                     7s 4 Value

D  Dec_lat2                      7s 4 Value

D  Dec_long2                     7s 4 Value

 *Assumptions

 * Formulas found at

 *http://williams.best.vwh.net/avform.htm#Intro

 *

 *The circumference of the earth in miles = 3954

 *

 *This program is based on The Great Circle Formula

 *d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))

 *

 *The as400 math functions work using Raidans so you have to convert

 *decimal to raidans.

 *The formula for converting decimal to raidans is

 * rad = dec * (pi/180)

 *

dpi               c                   3.14159265               
dradius           c                   3954                     
 *Point A                                                      
dlat1             s              8f                            
dlong1            s              8f                            
 *Point B                                                      
dlat2             s              8f                            
dlong2            s              8f                            
 * Result cosin Float long Point A & B                         
dtheta            s              8f                            
 * Work Fields                                                 
ddist             s              8f                            
dmiles            s              8s 4                          
                                                               
 *Prototypes for math functions                                
dsin              PR             8f   Extproc('sin')           
din                              8f   value                    
dcos              PR             8f   Extproc('cos')           
din                              8f   value                    
dacos             PR             8f   Extproc('acos')          
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++
din                              8f   value                
                                                           
 /free                                                     
                                                           
   //Convert Decimal to Float                              
   // Point A                                              
   lat1 = %float(Dec_Lat1);                                
   long1 = %float(Dec_long1);                              
   // Point B                                              
   lat2 = %float(Dec_lat2);                                
   long2 = %float(Dec_long2);                              
                                                           
   //Convert Decimal Degrees To Raidans                    
   // Point A                                              
   lat1 = lat1 * (pi/180);                                 
   long1 = long1 * (pi/180);                               
   // Point B                                              
   lat2 = lat2 * (pi/180);                                 
   long2 = long2 * (pi/180);                               
                                                           
   //Convert Raidans To Miles                                          
   theta = long1 - long2;                                              
   dist = radius * acos((sin(lat1)*sin(lat2))+                         
           (cos(lat1)*cos(lat2)*cos(theta)));                          
                                                                       
   //Convert Float To Decimal                                          
   miles = %dec(dist:8:4);                                             
                                                                       
   return    miles;                                                    
 /end-free                                                             
P Get_Miles       E                                                   

Bruce Odum
.Net\AS400 Programmer

-----Original Message-----
From: Karen Brasier [mailto:karen.brasier@xxxxxxxxx] 
Sent: Wednesday, January 12, 2005 2:23 PM
To: 'RPG programming on the AS400 / iSeries'
Subject: longitude / latitude distance calculations

Working on a project and need to know the distance in miles between two
locations.  The information that I have in the file to use to do this is
the
longitude and latitude.  I have seen the code in PC jargon, but have not
been able to find anything about how to accomplish this in RPG.    Any
suggestions would be appreciated... I am cutting/pasting the calc to
accomplish this below...    as I look at this, I am lost! (or worse,
lol)
surely, there is an easier way, but in searching the archives, I found
nothing on this... 
<snip>


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.