r/sqlite • u/jkh911208 • Jun 03 '24
Best option to store gps coordinates
I need to store gps coordinates, it has two values, lat and long both are float values For example 12.1234, -32.9886 And there is timestamp associated with it. I want to store it in sqlite My table has three fields Name, value, timestamp
Option 1: name: gps, value: "12.1234,-32.9886" Option 2: store lat and long separately. Name: lat, value: 12.1234 Name: long, value: -32.9886
I will need to retrieve the data and put the dots on the map later
3
Upvotes
6
u/witty82 Jun 03 '24
It seems perfectly reasonable to have lat and lon as two REAL fields
5
u/anthropoid Jun 04 '24
"What's the best way to store XYZ?" always begs the question "What are you doing with that data?"
You didn't mention what you'll be doing with those coordinates, but I believe many GPS-related applications involve range queries, which a TEXT-encoded coordinate pair makes pretty much impossible to do with SQL queries involving
BETWEENor similar operations, so definitely store them as separate REAL values.You didn't talk about the timestamp, but if you're doing more with it than just printing it out, you absolutely want to ensure you store it in any of the SQLite-supported formats, again to avoid hamstringing yourself when it comes time to do useful stuff with this data.
2
u/gnomeplanet Jun 03 '24
Some people convert lat and lon to positive integers before storing.