初学者: 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 编辑 ]