Android - Save location in SQLite database

android, database, sqldatatypes, sqlite

Solution

How can I read and write the correct number in the db?

I suggest you an one quick solution.

Since you know in what format you are storing your coordinates e.q. numbers so there is no problem to store them as `TEXT` and then retrieve them as `TEXT` and simple perform parsing back to `DOUBLE` if you'll want to do some stuff with them.

CREATE TABLE locs(
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   lat TEXT,
   lng TEXT,
   num INTEGER
)

Problem

I have problem with save latitude and longitude in SQLite database. I can save some location like (123.123999, 123.123999) and it will save in the database. But if I want to read it, I get rounded location like (123.124, 123.124). My table created by this sql segment: ``` CREATE TABLE locs(id INTEGER PRIMARY KEY AUTOINCREMENT, lat DOUBLE, lng DOUBLE, num INTEGER) ``` And querys results: ``` SELECT * FROM locs WHERE lat = 123.124; //RETURN NO ROWS SELECT * FROM locs WHERE lat = 123.123999; //RETURN 1 ROW ``` So I can't use the numbers I get to do queries on the data. I believe that I am not the first that handling with this problem, because it is basic thing. But I didn't found any answers that work on SQLite database. How can I read and write the correct number in the db?

Original source