$GPRMC解析(转)

 

计算距离

http://www.cnblogs.com/ycsfwhh/archive/2010/12/20/1911232.html

 

 

60进制就是时间中的分秒

0.629度*60=37.74分

0.74分*60=44.4秒

所以114.629度就是114度37分44.4

 

 

 

由于$GPRMC比较重要,所以重点讲解:

 http://blog.csdn.net/zccst/article/details/4235068

$GPRMC(Recommended Minimum Specific GPS/TRANSIT Data)

 

 

帧头

UTC时间

状态

纬度

北纬/南纬

经度

东经/西经

速度

$GPRMC

hhmmss.sss

A/V

ddmm.mmmm

N/S

dddmm.mmmm

E/W

 

 

 

方位角

UTC日期

磁偏角

磁偏角方向

模式

校验

回车换行

ddmmyy

000 - 180

E/W

A/D/E/N

*hh

CR+LF

 

 

格 式: $GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>*hh<CR><LF>

$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50

 

$GNRMC,080436.000,A,3641.111886,N,11704.436667,E,0.057,229.659,070116,,E,A*3E
3641.111886 36.6851981
11704.436667 117.07394445
对应的经纬度:36.6851981 117.07394445

 

说 明:

字段 0:$GPRMC,语句ID,表明该语句为Recommended Minimum Specific GPS/TRANSIT Data(RMC)推荐最小定位信息

          字段 1:UTC时间,hhmmss.sss格式

          字段 2:状态,A=定位,V=未定位

          字段 3:纬度ddmm.mmmm,度分格式(前导位数不足则补0)

          字段 4:纬度N(北纬)或S(南纬)

          字段 5:经度dddmm.mmmm,度分格式(前导位数不足则补0)

          字段 6:经度E(东经)或W(西经)

          字段 7:速度,节,Knots(一节也是1.852千米/小时)

          字段 8:方位角,度(二维方向指向,相当于二维罗盘)

          字段 9:UTC日期,DDMMYY格式

          字段10:磁偏角,(000 - 180)度(前导位数不足则补0)

          字段11:磁偏角方向,E=东,W=西

          字段12:模式,A=自动,D=差分,E=估测,N=数据无效(3.0协议内容)

          字段13:校验值

对应的程序代码如下:

     //运输定位数据
            private bool GPRMC_Parse(string data)
            {
                string[] source = Split(data, "$GPRMC");
                if (source != null && source.Length >= 12)
                {
                    //状态
                    this.AnchorState = source[2];
                    //纬度
                    if (source[4].Length > 0 && source[3].Length > 2)
                    {
                        this.Latitude = string.Format("{0}{1},{2}", source[4], source[3].Substring(0, 2), source[3].Substring(2));
                    }
                    else
                    {
                        this.Latitude = "";
                    }
                    //经度
                    if (source[6].Length > 0 && source[5].Length > 3)
                    {
                        this.Longitude = string.Format("{0}{1},{2}", source[6], source[5].Substring(0, 3), source[5].Substring(3));
                    }
                    else
                    {
                        this.Longitude = "";
                    }
                    //速度
                    if (source[7].Length > 0)
                    {
                        this.NSpeed = double.Parse(source[7]);
                    }
                   else
                    {
                        this.NSpeed = 0;
                    }
                    //方位
                    if (source[8].Length > 0)
                    {
                        this.Track = double.Parse(source[8]);
                    }
                    else
                    {

                       this.Track = 0;
                    }
                    //磁偏角和方位
                    if (source[10].Length > 0 && source[11].Length > 0)
                    {
                        this.Magnetic = string.Format("{0} {1}", source[11], source[10]);
                    }
                    else
                    {
                        this.Magnetic = "";
                    }
                    //模式
                    if (source.Length >= 13)
                    {
                        this.WorkMode = source[12];
                    }
                    //时间
                    try
                    {
                        if (source[9].Length == 6 && source[1].Length >= 6)
                        {
                            string dtString = string.Format("{0}-{1}-{2} {3}:{4}:{5}",
                                source[9].Substring(4),
                                source[9].Substring(2, 2),
                                source[9].Substring(0, 2),
                                source[1].Substring(0, 2),
                                source[1].Substring(2, 2),
                                source[1].Substring(4));
                            this.UTCDateTime = DateTime.Parse(dtString);
                        }
                    }
                    catch { return false; }
                    return true;
                }
                return false;
            }

 

posted @ 2016-01-14 14:49  星雷热忱  阅读(1115)  评论(0编辑  收藏  举报