I am attempting the code from this post:
I have a table "stations" that has the following fields:
id (DB_TEXT)
name (DB_TEXT)
lon (DB_TEXT)
lat (DB_TEXT)
My Code:
How do I obtain just one single lat/lon which is the nearest to: lat/lon.
B4X:
https://www.b4x.com/android/forum/threads/searching-the-nearest-coordinate-in-a-database.76833/#content
id (DB_TEXT)
name (DB_TEXT)
lon (DB_TEXT)
lat (DB_TEXT)
My Code:
B4X:
Sub btnNearest_Click
Dim lat As Float = -26.18586111 ' For example we want to find the nearest coordinate around this latitude
Dim lon As Float = 28.03805556 ' and this longitude
Dim c As Cursor
Dim latdist As Double = 1.0 / 111111.0 * 3.0;
Dim londist As Double = 1.0 / Abs(111111.0*Cos(lat)) * 3.0
c = Starter.SQL0.ExecQuery2($"SELECT * FROM stations WHERE lat BETWEEN ? AND ? AND lon BETWEEN ? AND ?;"$,Array As String(lat - latdist, lat + latdist , lon - londist, lon + londist))
For i = 0 To c.RowCount - 1
c.Position = i
LogColor("Nearest Lat: " & c.GetString("lat"), Colors.Blue)
LogColor("Nearest Lon: " & c.GetString("lon"), Colors.Blue)
Next
End Sub
How do I obtain just one single lat/lon which is the nearest to: lat/lon.