1

我正在尝试从 GPS 设备 (NMEA) 读取数据。我正在成功获取数据。但是,一旦我开始使用它,它就给我带来了胡言乱语。这是我从 GPS 得到的:

$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120556.000,A,2546.0985,S,02816.0193,E,0.22,276.44,291013,,,A*7A
$GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPGSV,3,1,12,31,50,165,19,14,48,055,27,16,43,304,42,32,36,265,38*76
$GPGSV,3,2,12,29,24,119,31,06,19,355,34,20,14,238,41,25,10,138,19*78
$GPGSV,3,3,12,27,09,351,33,22,06,008,36,03,05,341,36,23,,221,*7F
$GPRMC,120557.000,A,2546.0984,S,02816.0191,E,0.17,274.76,291013,,,A*7D
$GPGGA,120558.000,2546.0982,S,02816.0189,E,1,11,0.8,1396.0,M,21.5,M,,0000*72
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120558.000,A,2546.0982,S,02816.0189,E,0.07,220.52,291013,,,A*7B
$GPGGA,120559.000,2546.0981,S,02816.0187,E,1,11,0.8,1395.7,M,21.5,M,,0000*7A
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120559.000,A,2546.0981,S,02816.018

通过执行以下操作收到上述内容:

//inside a 100ms ticker
Dim data As String = GpsPort.ReadExisting()
CommentBox.AppendText(data)

一旦我这样做,Dim strArr() As String = data.Split("$")然后使用以下命令输出它:

CommentBox.AppendText(strArr(0).ToString) // inside the same ticker

输出是:

034.000,2546.0985,S,02816.0298,E,1,11,0.8,1360.6,M,21.5,M,,0000*77
3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
MC,121034.000,A,2546.0985,S,02816.0298,E,0.01,236.13,291013,,,A*75
.000,2546.0983,S,02816.0297,E,1,11,0.8,1359.9,M,21.5,M,,0000*7A
A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
,121035.000,A,2546.0983,S,02816.0297,E,0.06,283.04,291013,,,A*72
036.000,2546.0982,S,02816.0296,E,1,11,0.8,1359.3,M,21.5,M,,0000*73
3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
MC,121036.000,A,2546.0982,S,02816.0296,E,0.03,190.30,291013,,,A*72
.000,2546.0981,S,02816.0296,E,1,11,0.8,1358.6,M,21.5,M,,0000*75
A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
3,1,12,31,49,161,28,14,46,052,20,16,45,301,39,32,36,268,35*79
3,2,12,29,23,122,18,06,21,355,27,20,15,240,40,27,11,351,37*78

GPGGA谁能帮助我从字符串中获取 GPS 坐标?因为拆分它们显然是行不通的。

4

2 回答 2

1

您必须逐行读取数据。每行是一个 NMEA 句子。

一旦您检测到“$GPGGA”(或者您也可以使用 RMC 消息),您将拥有这一行:

$GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71

现在你用分隔符“,”分割

然后这是纬度:2546.0984,S
这是经度 02816.0191,E

在 NMEA 规范中读取坐标格式是:我认为:纬度中的第一个数字是度数,其余的是分钟:25° 46.0984 分钟。如果“S”将结果乘以 -1。

经度略有不同:02816.0191,E

前 3 位数度数,休息分钟。27° 16.0191 分钟。如果为“W”,则乘以 -1。

于 2013-10-29T15:24:41.957 回答
0

基本上,您看到的消息是相当复杂的消息格式的一部分。每个部分的含义不同,含义取决于消息类型。

您可能想查看此开源项目中的一些代码。我和一位同事一起编写了这个库,它解析了来自特定 GPS 设备的这些消息,但它几乎可以与任何输出相同数据的设备一起使用。

于 2013-10-29T14:49:24.727 回答