1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Calculates the distance between two points on Earth

Discussion in 'Delphi Programming' started by medreis, Nov 6, 2015.

  1. medreis
    Offline

    medreis DF Junior

    //With the code below you can calculate the distance between two points on the map

    Const
              pi      = 3.14159265358979323846;
              half_pi = 1.57079632679489661923;
              rad     = 3.14159265358979323846/180;{conversion factor for degrees into radians}
       
    Function atan2(y,x: extended): extended;
        begin 
          if x = 0.0 then
            begin
              if y = 0.0 then
                (* Error! Give error message and stop program *)
              else if y > 0.0 then
                atan2 := half_pi
              else
                atan2 := -half_pi
            end
          else
            begin
              if x > 0.0 then
                  atan2 := arctan(y/x)
              else if x < 0.0 then
                begin
                  if y >= 0.0 then
                    atan2 := arctan(y/x)+pi
                  else
                    atan2 := arctan(y/x)-pi
                end; 
            end;
        end; {atan2}


    //For Teste

    Var
       radius,lon1,lon2,lat1,lat2,dlon,dlat,a,distance :extended;

    Begin
       radius:=6378.137; {Earth equatorial radius in Km; as used in most GPS} 

       {Input here coordinates of the two points:}

       lon1:=-99.133333; {The Zocalo square, Mexico City}
       lat1:=19.432778;
       
       lon2:=-99.1862;   {The National Museum of Anthropology, Mexico City}
       lat2:=19.4260;

     {The Haversine formula}

       dlon:= (lon2-lon1)*rad;
       dlat:= (lat2-lat1)*rad;
       a:= sqr(sin(dlat/2)) + cos(lat1*rad)*cos(lat2*rad)*sqr(sin(dlon/2));
       distance:= radius*(2*atan2(sqrt(a),sqrt(1-a)));
      ShowMessage('Distance: '+ FloatToStr( round(distance*1000)) +'metros');
       End.
     


     
     
  2. ilanamlas1
    Online

    ilanamlas1 Guest

    good job
     
  3. pcesarlopes
    Online

    pcesarlopes Guest

    all right
     

Share This Page