程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi中利用MSCOMM控件進行GPS數據采集(2)

Delphi中利用MSCOMM控件進行GPS數據采集(2)

編輯:Delphi

3)為定時器Timer1添加OnTimer事件添加如下代碼:

procedure Tmainfrm.Timer1Timer(Sender: TObject);
var
i:integer;
tmpstr,strq,strq1,strq2,tmpstr1,tmpstr2:string;
latitudestr,longitudestr:string;
begin
i:=0;
gpsstr:=mscomm1.input;
gpsstrcpy:=gpsstr;
while strlen(pchar(gpsstr))>0 do begin
tmpstr:=copy(gpsstr,pos(#10,gpsstr),pos(#13,gpsstr)-1);
delete(gpsstr,1,pos(#10,gpsstr));
if copy(tmpstr,1,pos(',',tmpstr)-1)='$GPRMC' then begin
delete(tmpstr,1,pos(',',tmpstr));//,strlen(pchar(tmpstr))-pos(',',tmpstr)+1);
delete(tmpstr,1,pos(',',tmpstr));
if copy(tmpstr,1,pos(',',tmpstr)-1)='A' then begin
delete(tmpstr,1,pos(',',tmpstr));
latitudestr:=copy(tmpstr,1,pos(',',tmpstr)-1);
editlatitude.Text:='';
strq1:=copy(latitudestr,1,2); strq2:=copy(latitudestr,3,6);
editlatitude.Text:=strq1+'°'+strq2+'''';
weidud:=strtofloat(copy(latitudestr,1,2))+strtofloat(copy(latitudestr,3,6))/60;
weidud:=weidud*3.141592654/180;
delete(tmpstr,1,pos(',',tmpstr));
delete(tmpstr,1,pos(',',tmpstr));
longitudestr:=copy(tmpstr,1,pos(',',tmpstr)-1);
longitude:=strtofloat(copy(longitudestr,1,3))+strtofloat(copy(longitudestr,4,6))/60;
editlongitude.Text:='';
strq1:=copy(longitudestr,1,3); strq2:=copy(longitudestr,4,6);
editlongitude.Text:=strq1+'°'+strq2+'''';
jinchad:=abs(longitude-strtoint(centerlongitudestr));
jinchad:=jinchad*3.141592654/180;
end;
break;
end;
end;
n:=a/sqrt(1-firstpxl*sin(weidud)*sin(weidud));
sm:=6367558.496*weidud-16036.48*sin(2*weidud)+16.828*
  sin(4*weidud)-0.022*sin(6*weidud)+0.00003*sin(8*weidud);
nn:=sqrt(firstpxl)*cos(weidud);
x:=sm+n*sin(weidud)*cos(weidud)*jinchad*jinchad/2+n*jinchad*
  jinchad*jinchad*jinchad*sin(weidud)*cos(weidud)*cos(weidud)*cos(weidud)*(5-  
  tan(weidud)*tan(weidud)+9*nn*nn+4*nn*nn*nn*nn)/24+n*power(jinchad,6)*
  sin(weidud)*power(cos(weidud),5)*(61-58*tan(weidud)*tan(weidud)+tan(weidud)
  *tan(weidud)*tan(weidud)*tan(weidud)+270*nn*nn*nn*nn-330*nn*nn*tan(weidud)*tan(weidud))/270; //縱坐標
y:=n*jinchad*cos(weidud)+n*jinchad*jinchad*jinchad*cos(weidud)*cos(weidud)*cos(weidud)*(1-tan(weidud)*tan(weidud)+nn*nn)/6+n*power(jinchad,5)*power(cos(weidud),5)*(5-18*tan(weidud)*tan(weidud)+tan(weidud)*tan(weidud)*tan(weidud)*
tan(weidud)+14*nn*nn-58*nn*nn*tan(weidud)*tan(weidud))/120; //橫坐標
editxcoord.Text:=formatfloat('00000.00',x);
editycoord.Text:=formatfloat('00000.00',y);
end;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved