# Distance Calculator

#### PatrikL

##### Member
This sub is usable in GPS programs -
B4X:
``````Sub Calc
result.Text = sqrt(69.1 * (Lat2.Text - Lat1.Text) * 69.1 * (Lat2.Text - Lat1.Text) + 69.1 * (Lon2.Text - Lon1.Text) * cos(lat1.Text/57.3) * 69.1 * (Lon2.Text - Lon1.Text) * cos(lat1.Text/57.3))
End Sub``````
(Source: http://www.meridianworlddata.com/Distance-Calculation.asp )
- create 5x TextBox - Lat1,2; Lon1,2; result and one Button - Calc
My sample is here:

#### Attachments

• gpsdistance.zip
109.1 KB · Views: 360
Last edited:

#### sho431

##### New Member
Hi PatrikL

very good sample, but what about the direction.

Thanks
shooshan

#### PatrikL

##### Member
Good idea, i try to find formula via google

#### sho431

##### New Member
Good idea, i try to find formula via google

I need :sign0085:

B4X:
``````distanceEast=(Lon2.Text - Lon1.Text)
distanceNorth=(Lat2.Text - Lat1.Text)
direction= Atan(distanceNorth/distanceEast) Mod (2 * cPI)
direction = (direction)*(180/cPI)
If direction < 0 Then
direction+= 360
End If``````

#### Erel

##### B4X founder
Staff member
Longtime User
There is no += in Basic4ppc.

#### PatrikL

##### Member
2 sho431
- i try repair that sub, but it don't work :sign0085:
From where is that formula?

#### sho431

##### New Member
Hi

:sign0013:

From this
B4X:
``http://www.tma.dk/gps/#calcdir``