先买个GPS,接收GPS数据,估计下面的程序已经够你们用了。
unit Maps;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, ExtCtrls, StdCtrls, Buttons,comm232,ComObj, Menus, MapXLib_TLB,
Db, DBTables;
type
TMapsForm = class(TForm)
Timer1: TTimer;
Map1: TMap;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
Table1: TTable;
N8: TMenuItem;
N9: TMenuItem;
OpenDialog1: TOpenDialog;
Table_dtk: TTable;
Timer2: TTimer;
N10: TMenuItem;
PopupMenu1: TPopupMenu;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
N15: TMenuItem;
N16: TMenuItem;
N17: TMenuItem;
Panel1: TPanel;
Edit1: TEdit;
BitBtn1: TBitBtn;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure N7Click(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure N10Click(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure N12Click(Sender: TObject);
procedure N13Click(Sender: TObject);
procedure N14Click(Sender: TObject);
procedure N15Click(Sender: TObject);
procedure N16Click(Sender: TObject);
procedure N17Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Map1ToolUsed(Sender: TObject;
ToolNum: Smallint;
X1, Y1, X2,
Y2, Distance:do
uble;
Shift, Ctrl: WordBool;
var EnableDefault: WordBool);
private
{ Private declarations }
public
{ Public declarations }
Buf,Pb
byte;
BufLen,Len:integer;
procedure MovePoint(X, Y:do
uble);
//移动目标
procedure CheckPoint(var X, Y:do
uble;TempFeature:CMapXFeature);
//自动校位
end;
var
MapsForm: TMapsForm;
Device_AD:TComm232;
i:integer;
str_b1,str_b2:boolean;
jdz,wdz:double;
MapLayerAni:CMapXLayer;
//动画层
shijian:string;
path:string;
CurrentKey:integer;
x,y:double;
implementation
{$R *.DFM}
procedure TMapsForm.CheckPoint(var X, Y:do
uble;TempFeature:CMapXFeature);
begin
if (X>Map1.Bounds.XMax) or (X<Map1.Bounds.XMin) or (y>Map1.Bounds.yMax)or (y<Map1.Bounds.yMin) then
begin
//超出图形范围
Map1.CenterX:=TempFeature.Point.X;
Map1.CenterY:=TempFeature.Point.Y;
end
end;
procedure TMapsForm.MovePoint(X, Y:do
uble);
var
DrawPoint:CMapXPoint;
//创建点
CarFeature:CMapXFeature;
//点对象类型
TempFeature:CMapXFeature;
aaa:CMapXStyle;
begin
if CurrentKey>0 then
begin
//移动
TempFeature:=MapLayerAni.GetFeatureById(CurrentKey);
//在图形上得到需要移动的点对象
TempFeature.Point.Set_(X,Y);
//更改坐标
TempFeature.Update(EmptyParam, EmptyParam);
//更新图显示
end
else
begin
DrawPoint:=CoPoint.Create;
//创建点
DrawPoint.Set_(X,Y);
//GPS打点
CarFeature:=CreateOleObject('MapX.Feature.4') as CMapXFeature;
//创建图对象
aaa:=CreateOleObject('MapX.Style.4') as CMapXStyle;
aaa.SymbolType:=1;
aaa.SymbolBitmapTransparent:=true;
aaa.SymbolBitmapName:='stop1-32.BMP';
aaa.SymbolBitmapSize:=10;
Map1.DefaultStyle:=aaa;
CarFeature:= Map1.FeatureFactory.CreateSymbol(DrawPoint,Map1.DefaultStyle);
//点形状
TempFeature:=MapLayerAni.AddFeature(CarFeature,EmptyParam);
//加载到图形上
CurrentKey:=TempFeature.FeatureID;
//得到新加载图象的ID
end;
CheckPoint(X,y,TempFeature);
//判断是否超出窗口视图范围
end;
procedure TMapsForm.Timer1Timer(Sender: TObject);
var
zh,str2,str1,ad_c,wd,jd:string;
str_i,wd_n,jd_n,wxsl_n:integer;
begin
Device_AD.ReceRawData(Buf,Buflen);
if Buflen=0 then
begin
Device_AD.Destroy;
Device_AD:=TComm232.Create;
//初始化波形串口
Device_AD.Settings:=edit1.text+',115200,0,8,0';
//设置波形串口参数:端口名,速率,校验,数据位,停止位
Device_AD.PortOpen:=True;
Device_AD.SetCtrlSign(False,False);
timer1.Enabled:=true;
exit;
end;
Str1:='';
Str2:='';
str_b1:=false;
str_b2:=false;
str_i:=0;
if BufLen>0 then
begin
PB:=Buf;
for i:=0 to BufLen-1do
begin
Str2:=Str2+IntToHex(PB^,2);
if (str_b1=false) and (copy(str2,length(str2)-5,6)='404040') then
begin
str1:='';
str2:='';
str_b1:=true;
end;
if str_b1 then
begin
str_i:=str_i+1;
Str1:=Str1+IntToHex(PB^,2);
len:=41;
if (str_i=len) and (copy(str1,length(str1)-1,2)='23') then
begin
// 没有第二速度
str_b2:=true;
break;
end;
end;
Inc(PB);
end;
if (str_b2<>true) or (copy(str1,31,16)='3030303030303030') then
str1:='';
end;
if str_b2<>true then
begin
Timer1.Enabled :=true;
exit;
end;
//纬度
ad_c:=copy(str1,31,8);
if ad_c<>'' then
begin
insert('$',ad_c,1);
wd_n:=(strtoint(ad_c));
wd:=inttostr(strtoint(ad_c));
end else
begin
Timer1.Enabled :=true;
exit;
end;
//经度
try
ad_c:=copy(str1,39,8);
insert('$',ad_c,1);
jd_n:=strtoint(ad_c);
jd:=inttostr(strtoint(ad_c));
except
Timer1.Enabled :=true;
exit;
end;
//移动点
wdz:=strtoint(wd)/60000;
jdz:=strtoint(jd)/60000;
// table1.open;
Table1.Append;
Table1.FieldByName('jdz').asfloat:=jdz;
Table1.FieldByName('wdz').asfloat:=wdz;
Table1.Post;
// table1.Close;
if (jdz<0) or (jdz>360) then
exit;
if (wdz<0) or (wdz>90) then
exit;
MovePoint(jdz,wdz);
end;
procedure TMapsForm.FormCreate(Sender: TObject);
var shijian:string;
path:string;
begin
MapsForm.Left:=0;
MapsForm.Top:=0;
MapsForm.Width:=1024;
MapsForm.Height:=768;
Map1.Left:=0;
Map1.Top:=0;
Map1.Width:=1024;
Map1.Height:=768;
Device_AD:=TComm232.Create;
//初始化波形串口
Device_AD.Settings:=edit1.text+',115200,0,8,0';
//设置波形串口参数:端口名,速率,校验,数据位,停止位
if not Device_AD.PortOpen then
begin
Device_AD.PortOpen:=True;
Device_AD.SetCtrlSign(False,False);
end;
//初始化
Map1.Geoset:='d:/Maps/Map/china.gst';
//装载图
MapLayerAni :=Map1.Layers.CreateLayer('MapLayerAni', EmptyParam,1,EmptyParam, EmptyParam);
//创建动画层
Map1.RedrawInterval:=50;
//自动重绘周期
Map1.AutoRedraw:=True;
Map1.Layers.AnimationLayer:=MapLayerAni;
//指定当前动画层
Map1.TitleText:='';
Map1.CurrentTool:=miPanTool;
Map1.Align:=alclient;
end;
procedure TMapsForm.Button1Click(Sender: TObject);
begin
Map1.DefaultStyle.PickSymbol;
end;
procedure TMapsForm.N2Click(Sender: TObject);
begin
timer1.Enabled:=false;
close;
end;
procedure TMapsForm.N4Click(Sender: TObject);
begin
Map1.CurrentTool:=miZoomInTool;
end;
procedure TMapsForm.N6Click(Sender: TObject);
begin
Map1.CurrentTool:=miPanTool
end;
procedure TMapsForm.N5Click(Sender: TObject);
begin
Map1.CurrentTool:=miZoomOutTool;
end;
procedure TMapsForm.N7Click(Sender: TObject);
begin
Map1.DefaultStyle.PickSymbol;
end;
procedure TMapsForm.N9Click(Sender: TObject);
var ml_c:string;
ml_c1:string;
ml_c2:string;
hf_wjm,hf_ml:string;
begin
timer1.Enabled:=false;
opendialog1.Filter:='*.db';
opendialog1.FileName:='*.db';
if opendialog1.Execute then
begin
//获得目录、文件名
ml_c:='';
ml_c1:='';
ml_c2:='';
hf_ml:='';
hf_wjm:='';
ml_c:=opendialog1.files[0];
while pos('/',ml_c)<>0do
begin
ml_c1:=copy(ml_c,1,pos('/',ml_c));
ml_c2:=copy(ml_c,pos('/',ml_c)+1,100);
hf_ml:=hf_ml+ml_c1;
ml_c:=ml_c2;
end;
hf_wjm:=ml_c;
table_dtk.close;
table_dtk.DataBaseName:='d:/maps/db/';
table_dtk.TableName:=(hf_wjm);
table_dtk.open;
table_dtk.First;
timer2.Enabled:=true;
end;
end;
procedure TMapsForm.Timer2Timer(Sender: TObject);
begin
wdz:=table_dtk.fieldbyname('wdz').asfloat;
jdz:=table_dtk.fieldbyname('jdz').asfloat;
if (jdz<0) or (jdz>360) then
exit;
if (wdz<0) or (wdz>90) then
exit;
MovePoint(jdz,wdz);
table_dtk.Next;
end;
procedure TMapsForm.N10Click(Sender: TObject);
begin
shijian:=formatdatetime('yyyymmddss',now);
path:=extractfilepath(application.ExeName);
//系统路径
Table1.close;
Table1:=TTable.Create(nil);
Table1.DataBaseName:=path+'db';
Table1.TableType:=ttDefault;
Table1.TableName:=shijian+'.db';
Table1.Close;
Table1.FieldDefs.Clear;
Table1.FieldDefs.Add('jdz',ftfloat,0,False);
//0
Table1.FieldDefs.Add('wdz',ftfloat,0,False);
//1
Table1.CreateTable;
Table1.open;
Timer1.Enabled:=true;
end;
procedure TMapsForm.N11Click(Sender: TObject);
begin
shijian:=formatdatetime('yyyymmddss',now);
path:=extractfilepath(application.ExeName);
//系统路径
Table1.close;
Table1:=TTable.Create(nil);
Table1.DataBaseName:=path+'db';
Table1.TableType:=ttDefault;
Table1.TableName:=shijian+'.db';
Table1.Close;
Table1.FieldDefs.Clear;
Table1.FieldDefs.Add('jdz',ftfloat,0,False);
//0
Table1.FieldDefs.Add('wdz',ftfloat,0,False);
//1
Table1.CreateTable;
Table1.open;
Timer1.Enabled:=true;
end;
procedure TMapsForm.N12Click(Sender: TObject);
begin
Map1.CurrentTool:=miZoomInTool;
end;
procedure TMapsForm.N13Click(Sender: TObject);
begin
Map1.CurrentTool:=miZoomOutTool;
end;
procedure TMapsForm.N14Click(Sender: TObject);
begin
Map1.CurrentTool:=miPanTool
end;
procedure TMapsForm.N15Click(Sender: TObject);
begin
Map1.DefaultStyle.PickSymbol;
end;
procedure TMapsForm.N16Click(Sender: TObject);
begin
close;
end;
procedure TMapsForm.N17Click(Sender: TObject);
begin
panel1.Visible:=true;
end;
procedure TMapsForm.BitBtn1Click(Sender: TObject);
begin
panel1.Visible:=false;
end;
procedure TMapsForm.Map1ToolUsed(Sender: TObject;
ToolNum: Smallint;
X1,
Y1, X2, Y2, Distance:do
uble;
Shift, Ctrl: WordBool;
var EnableDefault: WordBool);
begin
x:=x1;
y:=y1;
end;
end.