Location latitude and longitude from location sensor not writing to Sqlite

Hi, I can't get app inventor to write the longitude and latitude from the location sensor to sqlite. I can print the lat and lon to the screen and use them to plot an open map marker. The same variable is used to write to sqlite, but in the DB it only writes the values I initiated the variable with.

Try putting all your blocks in the LocationChanged event

Show your full SQL statement for inserting values....

Thx for quick reply @TIMAI2. The blocks are running in a clock, because they need to integrate Arduino data. I imagine trying to write to the same DB row from two different places in the code would be difficult.
This is the SQL statement, that works fine. I just get the wrong values for the lat and lon. Instead of the actual values that I see on the screen, the DB registers the value of initialisation of the global latitude and global longitude variables.

Forgot the SQL: INSERT INTO data(time, session, depth, confidence, pressure, latitude, longitude, accuracy) VALUES(

Also, I do get the accuracy value from the location sensor correctly.

One guess is that you put single quotes around the time value, but no single quotes for the other variables. sqLite is expecting strings or numbers....

The single quotes are around the session value, because that is a string. The other values are numbers, and are written to the DB without error. The problem is that the value for lat should come from the value of "global latitude", but instead of writing the value that is shown in the lable or used for the map, it keeps writing the initial value of the variable. To me it looks like some kind of bug, as there is no logic in getting different values from the same variable.

As previously suggested, try running your blocks in the LocationChanged event, after getting the new lat and lon....the clock might be firing before the location has changed.....

or at least start the clock after the location has changed and new co-ordinates are set to the lat/lon variables

Why are you using a temporary list? Just write the data directly... or empty the list before writing again... your list is filling up more and more and you are reading always only the first values

Taifun

1 Like

Thank you Taifun. I copied this code to not work with the arduino and disabled the other block. I forgot to copy the empty list block. :sweat:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.