Follow the full code based on the contribution of colleague Tmc, ready to test
In a blank form:
copy the code below and press Ctrl+V (Paste)
object Edit1: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 0
KeyboardType = NumberPad
Text = '41.500605'
Position.X = 56.0
Position.Y = 56.0
TextPrompt = 'Latitude1'
end
object Edit2: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 1
KeyboardType = NumberPad
Text = '-7,731313'
Position.X = 56.0
Position.Y = 80.0
TextPrompt = 'Longitude1'
end
object Edit3: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 2
KeyboardType = NumberPad
Text = '37,186851'
Position.X = 56.0
Position.Y = 128.0
TextPrompt = 'Latitude2'
end
object Edit4: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 3
KeyboardType = NumberPad
Text = '-8,742056'
Position.X = 56.0
Position.Y = 152.0
TextPrompt = 'Longitude2'
end
object Button1: TButton
Position.X = 56.0
Position.Y = 184.0
TabOrder = 4
Text = 'Distancia'
OnClick = Button1Click
end
object Label1: TLabel
Position.X = 56.0
Position.Y = 40.0
Text = 'Coordenada A'
end
object Label2: TLabel
Position.X = 56.0
Position.Y = 112.0
Text = 'Coordenada B'
end
object Label3: TLabel
Position.X = 56.0
Position.Y = 216.0
end
Paste the following code below implementation, then press Shift+Ctrl+C to create the signatures
function CalcDistanciaCoord(Lat1,Lng1,Lat2,Lng2:Double):Double;//Retorna distancia em Km
const
r:Double = 6371.0;//Raio da terra
var
Val, Lng, Lat: Double;
piLat1,piLng1,piLat2,piLng2:Double;
function sgn(a: real): real;
begin
//if a < 0 then sgn := -1 else sgn := 1;
result := a/abs(a)
end;
function atan2(y, x: real): real;
begin
if x > 0 then atan2 := arctan(y/x)
else if x < 0 then atan2 := arctan(y/x) + pi
else atan2 := pi/2 * sgn(y);
end;
begin
piLat1 := Lat1 * pi / 180.0;
piLng1 := Lng1 * pi / 180.0;
piLat2 := Lat2 * pi / 180.0;
piLng2 := Lng2 * pi / 180.0;
Lat := Lat2 - Lat1;
Lng := Lng2 - Lng1;
Val := sin(Lat / 2) * sin(Lat / 2) + cos(Lat1) * cos(Lat2) * sin(Lng / 2) * sin(Lng / 2);
Val := 2 * ATan2(sqrt(Val), sqrt(1 - Val));
Result:= r * Val;
end;
procedure TForm1.Button1Click(Sender: TObject);
var d,La1,Lo1,La2,Lo2:Double;
begin
La1 := StrToFloat(Edit1.text);
Lo1 := StrToFloat(Edit2.text);
La2 := StrToFloat(Edit3.text);
Lo2 := StrToFloat(Edit4.text);
d:=CalcDistanciaCoord(La1,Lo1,La2,Lo2);
label3.text:=formatfloat('#0.000000 Km',d);
//label1.caption:=formatfloat('#0.000000 Km",d);//VCL
end;
http://www.tdevrocks.com.br/2014/09/26/quick-post-likesaber-distance-entre-dois-pontos-no-mapmap/ see if this helps you.
– Pablo Tondolo de Vargas
I’ll test it, thank you.
– R.Gasparin
@R.Gasparin just mark the solution as accepted, need not and should not touch the title.
– Bacco