Using OSMDroid 4.1.
It looks OSMDroid_GeoPoint latitude and longitude doesn't have the same floating point precision as B4A's Double or SQLite's Real and that can cause problems if you are not aware of it.
This code demonstrates the problem:
Log output:
TestFloatingPoint, GeoPoint1.Latitude: 52.594629, GeoPoint1.Longitude: -2.179047
TestFloatingPoint, Cursor1.RowCount: 0
TestFloatingPoint, dLatitude: 52.594629, dLongitude: -2.1790476
TestFloatingPoint, Cursor1.RowCount: 1
I can avoid this problem by keeping in SQLite (so do the equality test in SQLite) or maybe I could
use a custom Geopoint type, which will use B4A's Double data type.
Is this a bug in OSMDroid_GeoPoint?
Has anybody come across this problem?
RBS
It looks OSMDroid_GeoPoint latitude and longitude doesn't have the same floating point precision as B4A's Double or SQLite's Real and that can cause problems if you are not aware of it.
This code demonstrates the problem:
B4X:
Sub TestFloatingPoint
Dim strSQL As String
Dim Cursor1 As Cursor
Dim GeoPoint1 As OSMDroid_GeoPoint
Dim dLatitude As Double
Dim dLongitude As Double
strSQL = "CREATE TABLE IF NOT EXISTS TEST_FLOAT([ID] INTEGER, [LATITUDE] REAL, [LONGITUDE] REAL)"
General.SQL1.ExecNonQuery(strSQL)
strSQL = "DELETE FROM TEST_FLOAT"
General.SQL1.ExecNonQuery(strSQL)
strSQL = "INSERT INTO TEST_FLOAT(ID, LATITUDE, LONGITUDE) VALUES(1, 52.594629, -2.1790476)"
General.SQL1.ExecNonQuery(strSQL)
strSQL = "SELECT LATITUDE, LONGITUDE FROM TEST_FLOAT"
Cursor1 = General.SQL1.ExecQuery(strSQL)
Cursor1.Position = 0
GeoPoint1.Initialize(Cursor1.GetDouble2(0), Cursor1.GetDouble2(1))
dLatitude = Cursor1.GetDouble2(0)
dLongitude = Cursor1.GetDouble2(1)
strSQL = "SELECT ID FROM TEST_FLOAT WHERE LATITUDE = ? AND LONGITUDE = ?"
Cursor1 = General.SQL1.ExecQuery2(strSQL, Array As String(GeoPoint1.Latitude, GeoPoint1.Longitude))
Cursor1.Position = 0
General.RunLog("TestFloatingPoint, GeoPoint1.Latitude: " & GeoPoint1.Latitude & ", GeoPoint1.Longitude: " & GeoPoint1.Longitude)
General.RunLog("TestFloatingPoint, Cursor1.RowCount: " & Cursor1.RowCount)
Cursor1 = General.SQL1.ExecQuery2(strSQL, Array As String(dLatitude, dLongitude))
Cursor1.Position = 0
General.RunLog("TestFloatingPoint, dLatitude: " & dLatitude & ", dLongitude: " & dLongitude)
General.RunLog("TestFloatingPoint, Cursor1.RowCount: " & Cursor1.RowCount)
Cursor1.Close
End Sub
Log output:
TestFloatingPoint, GeoPoint1.Latitude: 52.594629, GeoPoint1.Longitude: -2.179047
TestFloatingPoint, Cursor1.RowCount: 0
TestFloatingPoint, dLatitude: 52.594629, dLongitude: -2.1790476
TestFloatingPoint, Cursor1.RowCount: 1
I can avoid this problem by keeping in SQLite (so do the equality test in SQLite) or maybe I could
use a custom Geopoint type, which will use B4A's Double data type.
Is this a bug in OSMDroid_GeoPoint?
Has anybody come across this problem?
RBS