首页 > 解决方案 > 将接收到的坐标存储到 SQLite 数据库

问题描述

我的电话号码收到 LAT 和 LONG 的短信。示例文本:

纬度:23.424076 经度:53.847818

我看到了一个关于如何将这些数据传递到 SQLite 数据库的教程。但是,它会读取所有传入的消息。我想从一个数字中获取这些数据。

本教程https://pankajkakade101.wordpress.com/2013/04/11/read-each-new-incoming-sms-massages-in-android-and-put-it-into-database-using-service/

一张桌子上有 3 列。一个用于地址、日期和正文。我希望我的应用程序识别正文(消息)是否有纬度和经度,并获取浮点数,并将其放在我桌子上的单独列上。

这很令人困惑。你能建议我应该怎么做吗?

标签: androidsqlitebroadcastreceiver

解决方案


考虑到您将始终收到消息文本为“LAT:”“LONG:”

String str = "LAT: 23.424076 LONG: 53.847818";
String[] splits = str.split("LAT: | LONG: ");

//test with
for(String s : splits)
    System.out.println(s);
   //Do your necessary jobs with the values over here

推荐阅读