today i was in the requrement to write a search-routine in Database.
given was a table with lat an lon values. Goal was to find the nearest Entry.
Tablename: nw05
Fields: gidx (index), glat (Latitude), glon (longitude), gval (the value we want to get)
Source of solution: http://stackoverflow.com/questions/...ite-by-nearest-latitude-longitude-coordinates
B4A Code to do the search in a already opened SqLite Database
given was a table with lat an lon values. Goal was to find the nearest Entry.
Tablename: nw05
Fields: gidx (index), glat (Latitude), glon (longitude), gval (the value we want to get)
Source of solution: http://stackoverflow.com/questions/...ite-by-nearest-latitude-longitude-coordinates
B4A Code to do the search in a already opened SqLite Database
B4X:
Dim lat As Float = 51.6916667 ' For example we want to find the nearest coordinate around this ltitude
Dim lon As Float = 11.3375 ' 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 = sql.ExecQuery2($"SELECT * FROM nw05 WHERE glat BETWEEN ? AND ? AND glon BETWEEN ? AND ?;"$,Array As String(lat - latdist, lat + latdist , lon - londist, lon + londist))
For i = 0 To c.RowCount - 1
c.Position = i
Log(c.GetString("gval"))
Next