# Android QuestionDistance in Km/h in 2 coordinates

#### Situ LLC

##### Active Member
Distance in Km/h in 2 coordinates
Another way to calculate the distance between 2 coordinates, is very accurate.

Dim Distancias2 As Double

Dim lat As String = \$"lat=\${Location1.Latitude}"\$
Dim lng As String = \$"lon=\${Location1.Longitude}"\$

This ones source to compared
<Lat2s, Lon2s>

#### Distancias2= Haversine( lat, lng , Lat2s, Lon2s)​

coordinates GPS:
``````rivate Sub Haversine(lat1 As Double, lon1 As Double, lat2 As Double, lon2 As Double) As Double
' Convert latitude and longitude from degrees to radians

' Haversine formula
Dim a As Double = Power(Sin(dlat / 2), 2) + Cos(lat1Rad) * Cos(lat2Rad) * Power(Sin(dlon / 2), 2)
Dim c As Double = 2 * ATan2(Sqrt(a), Sqrt(1 - a))

[B]'  the result changing  radiusOfEarth by   6371 km , 3959 millas or  Meters 6717407.00 [/B]

Dim distance As Double = radiusOfEarth * c

Return distance
End Sub

Private Sub DegreesToRadians(degrees As Double) As Double
Dim Pi As Double = 3.141592653589793238462643
Return degrees * (Pi / 180)
End Sub``````

Enjoy
Regard

Last edited:

Replies
2
Views
973
Replies
6
Views
2K
Replies
2
Views
3K
Replies
3
Views
2K
Replies
14
Views
10K