如何从GPS(NMEA)设备读取位置数据?

时间:2013-10-29 12:12:10

标签: vb.net visual-studio-2010 gps

我正在尝试从GPS设备(NMEA)读取数据。我成功地获得了数据。但是,一旦我开始使用它,它就会给我gibbirish。这是我从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坐标吗?因为清楚地拆分它们不起作用。

2 个答案:

答案 0 :(得分: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规范中读取坐标的格式:我认为:latitdue中的第一个数字是度,其余是分钟:25°46.0984分钟。如果“S”将结果乘以-1。

经度略有不同: 02816.0191,E

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

答案 1 :(得分:0)

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

您可能需要查看this open source project中的部分代码。我和一位同事一起编写了这个库,它从特定的GPS设备中解析出这些消息,但它几乎可以与任何设备发出相同的数据。