| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2300 人关注过本帖
标题:初学者: gps:GPRMC 经纬度问题
取消只看楼主 加入收藏
Rick_gu
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:37
专家分:108
注 册:2014-5-29
收藏
 问题点数:0 回复次数:0 
初学者: gps:GPRMC 经纬度问题
int gps_parse_line(struct gps_t *gps, char *buffer, int size)
{
    float lon, lat;
    char gps_status;   
    char n=0,m=0,f=0;  
    if((buffer[1] == 'G')   
        &&(buffer[2] == 'P')   
        &&(buffer[3] == 'R')   
        &&(buffer[4] == 'M')   
        &&(buffer[5] == 'C'))//GPRMC   
    {   
        for(n=0;n<100;n++)   
        {      
            if(buffer[n] == ',')   
            {   
                m ++;

                if(m == 2)
                {   
                    gps_status = buffer[n+1];                  
                }   
                if(m == 3)
                {   
                    if(gps_status == 'A')   
                    {   
                        lat =((float)(buffer[n+1])
                            +(float)(buffer[n+2])   
                            +(float)(buffer[n+3])
                            +(float)(buffer[n+4])
                            +(float)(buffer[n+6])
                            +(float)(buffer[n+7])
                            +(float)(buffer[n+8])
                            +(float)(buffer[n+9]));
                                                   
                    }   
                }   
                if(m == 4)   
                {   
                    "N";   
                }   
                if(m == 5)
                {   
                    
                    lon =((float)(buffer[n+1])  
                        +(float)(buffer[n+2])   
                        +(float)(buffer[n+3])  
                        +(float)(buffer[n+4])
                        +(float)(buffer[n+5])
                        +(float)(buffer[n+7])
                        +(float)(buffer[n+8])
                        +(float)(buffer[n+9])
                        +(float)(buffer[n+10]));
                    
                      }   
                if(m == 6)   
                {   
                    "E";   
                }   
            }   
        }   

    }   
    gps->lat=lat;
    gps->lon=lon;
   
    return 0;
}

int gps_get(struct gps_t *gps, float *lon, float *lat)
{
   
    *lon=gps->lon;
    *lat=gps->lat;
    return 0;
}



main:

int main(int argc, char *argv[])
{

    float lon, lat;
    struct gps_t gps;
    char *buffer = "$GPRMC,013946.00,A,3202.1855,N,11849.0769,E,0.05,218.30,111105,4.5,W,A*20";
   
    gps_parse_line(&gps, buffer, strlen(buffer));
    gps_get(&gps, &lon, &lat);
    printf("lon: %f, lat: %f\n", lon, lat);
    getchar();


为什么:      纬度:lat 开始值3202.1855     到 gps->lat=lat;  
              经度:lon开始值 11849.0769    到 gps->lon=lon;
lat值变为410.000000;
lon值变为477.000000;
debug时  gps->lat显示         : gps->lat    -1.0737418e+008    float



[ 本帖最后由 Rick_gu 于 2014-5-29 15:40 编辑 ]
搜索更多相关主题的帖子: 经纬度 
2014-05-29 14:47
快速回复:初学者: gps:GPRMC 经纬度问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023837 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved