如何将从移动GPS读取的LAT/LON信息存储到SQLITE数据库中?
我构建了读取当前位置(每10-20米)的坐标的应用程序,当移动移动在街道上并显示当前的LAT/LON时,现在我想开发将这些LAT/LON保存到SQLITE数据库中的应用程序。任何帮助(指南)作为起点将不胜感激。
i build app that read coordinates of current location (every 10-20 meters) when move mobile in streets and displays current lat/lon, now i would like to develop app that save (storing) these lat/lon into a sqlite database. Any help (guide) as starting point would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要设计数据库架构。仅存储lat/lon可能会毫无用处。您说每10-20米,所以还有其他东西,也许是时候使LAT/LON有用。
因此,假设时间是与LAT/LON相结合的因素使其有用。然后,您需要存储LAT,LON和时间。
因此,这将是您的模式中的3列,因为ROWID(一个特殊的列)都包含在所有表中(一些较少使用的例外)。然后4列(ROWID唯一标识一行)。
因此您的模式可能是: -
下一阶段,即执行所有数据库处理内容。通过扩展SQLiteOpenhelper类,可以极大地简化这一点。
因此,您可以参加这样做的课程。该类必须实现两种越过的方法 ongreate 和 onupgrade 。
您可能想最大程度地减少数据库的开放和关闭,因为这两者都可能是相对饥饿的资源。因此,建议采用单身方法,而无需关闭数据库。
您可能希望包括访问同类数据库(CRUD)的方法。
因此,将上述所有内容放在一起,例如 dbhelper as: -
dbhelper不会独自一人做任何事情,所以这里是利用它的示例。这将插入一些数据(2行),然后提取数据并将其写入日志: -
结果: -
当运行2行插入2行时,第二行有一个时间1小时。 。然后提取数据(对于10小时前到将来1小时之间的行(所有均为fir均为此标准的行))。但是,由于它们是根据时间戳(按升序(默认)(默认值)进行排序的,第二行将首先显示。
因此,日志包括(如预期): -
First you would need to design the database schema. Storing just lat/lon would probably be pretty useless. You say every 10-20 meters, so there is something else, perhaps the time that makes the lat/lon useful.
So assuming that time is the factor that in conjuntion with the lat/lon makes it useful. Then per row you would want to store the lat, lon and time.
So that would be 3 columns in your schema, as the rowid (a special column) is included in all tables (with some less frequently used exceptions). Then 4 columns (the rowid uniquely identifies a row).
So your schema could be :-
Th next stage is to do all the database handling stuff. This is greatly simplified by extending the SQLiteOpenHelper class.
So you can have a class that does this. That class MUST implement two overiding methods onCreate and onUpgrade.
You probably want to minimise the opening and closing of the database as both can be relatively resource hungry. So a singleton approach without any closing of the database is recommended.
You may wish to include the methods that access the database (the CRUD) in the class.
So putting all the above together you could have, for example the class DBHelper as :-
The DBHelper will do nothing on it's own so here's an example of utilising it. This will insert some data (2 rows) and then extract the data and write it to the log:-
Result :-
When run 2 rows will be inserted the 2nd row have a time 1 hour before the first. Then the data is extracted (for rows between 10 hours ago and 1 hour in the future (all rows as both fir this criteria)). However, as they are ORDERED according to the timestamp (in ascending order (the default)) the 2nd row is shown first.
The log thus includes (as expected):-