android RegEx外置GPS字符串

时间:2012-09-21 12:35:14

标签: android regex gps

我在从外部GPS流中获取的字符串中分离信息时遇到问题。

下面是一个字符串示例:

$GPGSV,3,3,12,22,09,276,31,25,24,247,24,27,54,131,,32,04,359,19*71
$GPGLL,5703.85365,N,00953.88360,E,075510.00,A,A*69
$GPPWR,028a,1,0,1,1
$GPRMC,075511.00,A,5703.85369,N,00953.88430,E,0.335,302.17,070912,,,A*6E
$GPVTG,302.17,T,,M,0.335,N,0.621,K,A*3A

我想要做的就是让“$GPGLL,5703.85365,N,00953.88360,E,075510.00,A,A*69”出来,这样我就可以获取经度和纬度,然后用它来更新我的textview。但是继续从bounch exeption中获取字符串,我开始怀疑我是否以错误的方式处理这个问题。

任何可以帮我解决问题的人都会找到正确的方向吗?

1 个答案:

答案 0 :(得分:0)

这是一种直接从GPS处理NMEA句子的方法:

    // Listener for NMEA sentences
public void  onNmeaReceived(long timestamp, String nmea) {
            // Split the sentence into its comma-separated pieces
    String [] sentence = nmea.split(",");
            // See if it's the sentence we're interested in
    if(sentence[0].equalsIgnoreCase("$GPGLL")) {
    /* In here, process the data components of the sentence, which will
               be in sentence[1], sentence[2], etc. */
        }
    }
}