Sub FindNearest( ) As Boolean
Dim i As Int
Dim lastloc, lloc As Double
Dim fnd As Boolean
Dim Ca As Cursor
Log(" GPS Status: " & GPSServMod.fSats)
fnd = False
cl = "No Location Found"
If GPSServMod.gLoc.fAccuracyValid = False Then
Log(" GPS not Locked " & GPSServMod.fSats)
DoEvents
Return fnd
Else
lat1 = GPSServMod.gLoc.fLatitude
lon1 = GPSServMod.gLoc.fLongitude
lat2 = lat1
lon2 = lon1
m = .5
End If
Ca = SQL2.ExecQuery2( "SELECT * FROM Location WHERE latitude <= ? and latitude >= ? and longitude >= ? and longitude <= ? order by city", Array As String(lat1 + m, lat2 - m, lon1 - m, lon2 + m ) )
lloc = 100000000.0
If Ca.RowCount > 0 Then
For i = 0 To Ca.RowCount - 1
Ca.Position = i
lastloc = Geo1.distanceToMidpoint(lat2, lon2, Ca.GetDouble("latitude"),Ca.GetDouble("longitude"))
If lastloc <= lloc Then
cl = Ca.GetString("city")&", "&Ca.GetString("region")
lloc = lastloc
End If
Next
CurrLoc = cl
Log(" Found Many Locations: " & Ca.RowCount)
fnd = True
Else
m = m + .5
End If
Ca.Close
Return fnd
End Sub