Android Question Floating point problem with OSMDroid_GeoPoint

RB Smissaert

Well-Known Member
Licensed User
Longtime User
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:

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
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hi.

Could you share the osm libraries?

Thanks

Attached a .zip with first lot the files. They will all need to go to your AdditionalLibraries folder.
Zip got too big with all files, so will send another zip.

RBS
 

Attachments

  • AdditionalLibraries.zip
    373.1 KB · Views: 316
Upvote 0

carlos7000

Well-Known Member
Licensed User
Longtime User
Hi.

Thank you very much for your interest.

I tell him that I thought they were the libraries that I needed. They were not. But I already got them.

The project is old. It is several years old. It is one of my first programs. I was checking the code and it's terrible.

Try to compile the project. With each attempt, the compiler complained about something. already corrected everything the compiler complained about. The project compiles, but does not show the map.

Thanks.
 
Upvote 0
Top