0

我在从外部 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”拿出来,这样我就可以抓住经度和纬度,然后用它更新我的文本视图。但是不断地从 bounch exeption 中获取字符串,我开始怀疑我是否以错误的方式处理这个问题。

任何人都可以让我在如何解决这个问题上朝着正确的方向前进?

4

1 回答 1

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. */
        }
    }
}
于 2012-09-22T21:35:13.390 回答