Hi Guys

I'm busy converting one of my windows Coordinates Programs for Racing Pigeons from a Windows program to B4A

I got stuck with some calc convertions.

Please see the code and advice. Appreciate

'* - lines working

'X - lines with errors

If interested, here is my original WIndows App

www.leznadsoftware.co.za/downloads/calcdist.zip

This program is pretty accurate, for distance between 2 Coordinates

Thanks, Appreciate

Danie

I'm busy converting one of my windows Coordinates Programs for Racing Pigeons from a Windows program to B4A

I got stuck with some calc convertions.

B4X:

```
sub Globals
Dim Deg2Rad As Double 'EQUATE(.0174532925199) ! number of degrees In a radian
Dim a As Double ' EQUATE(6378.14) ! the earth's radius in kilometers
Dim fl As Double ' EQUATE(.003352813) ! the earth's flattening
Dim lat1 As Double ' REAL ! latitude of departure
Dim lat2 As Double
Dim North1 As Long ' Short(0) ! latitude of departure Northern Hemisphere
Dim South1 As Long ' Short(1) ! latitude of departure Southern Hemisphere
Dim West1 As Long ' Short(0) ! longitude of departure Western Hemisphere
Dim East1 As Long ' Short(1) ! longitude of departure Eastern Hemisphere
Dim lon1 As Double ' REAL ! longitude ofdeparture
Dim North2 As Long ' Short(0) ! latitude of destination Northern Hemisphere
Dim South2 As Long ' Short(1) ! latitude of destination Southern Hemisphere
Dim West2 As Long ' Short(0) ! longitude of destination Western Hemisphere
Dim East2 As Long ' Short(1) ! longitude of destination Eastern Hemisphere
Dim lon2 As Double ' REAL ! longitude of destination
Dim F As Double ' REAL ! (lat1 + lat2)/2
Dim G As Double ' REAL ! (lat1 - lat2)/2
Dim lambda As Double ' REAL ! (lon1 - lon2)/2
Dim S As Double ' REAL
Dim C As Double ' REAL
Dim tan_omega As Double ' REAL
Dim omega As Double ' REAL
Dim R As Double ' REAL
Dim D As Double ' REAL ! approxomite Distance In kilometers
Dim H1 As Double ' REAL
Dim H2 As Double ' REAL
Dim km As Double ' decimal(12,3)!REAL(0) ! the Distance In kilometers
Dim mi As Double ' REAL(0) ! the Distance In miles
Dim Meter As Double ' Decimal(12,2)
Dim coord As Double
end sub
```

Please see the code and advice. Appreciate

'* - lines working

'X - lines with errors

B4X:

```
Sub Distance
F = (lat1 + lat2)/2 '*
G = (lat1 - lat2)/2 '*
lambda = (lon1 - lon2)/2
' convert To radians
F *= Deg2Rad 'X
G *= Deg2Rad 'X
lambda *= Deg2Rad 'X
S = Sin(G)^2 * Cos(lambda)^2 + Cos(F)^2 * Sin(lambda)^2 'X
C = Cos(G)^2 * Cos(lambda)^2 + Sin(F)^2 * Sin(lambda)^2 'X
tan_omega = Sqrt(S/C) '*
omega = ATan(tan_omega) '! In radians '*
D = 2*omega*a ' approximate Distance In kilometers '*
R= Sqrt(S*C)/omega '*
H1 = (3*R - 1)/(2*C) '*
H2 = (3*R + 1)/(2*S) '*
km = D *(1 + fl*H1*Sin(F)^2 * Cos(G)^2 - fl*H2*Cos(F)^2 * Sin(G)^2) 'X
mi = km/1.609344
Meter = km * 1000
End Sub
```

If interested, here is my original WIndows App

www.leznadsoftware.co.za/downloads/calcdist.zip

This program is pretty accurate, for distance between 2 Coordinates

Thanks, Appreciate

Danie

Last edited: