我写了一个小测试程序来解析我的车辆登记程序中的目的地,并将用户输入的km与google km进行比较。我的问题是如果我在每个GMDirection1.Execute之后不使用sleep(800);我每次都得到这个确切的错误: https://maps.gstatic.com/cat_js/intl/de_de/mapfiles/api-3/15/11/%7Bmain,geometry,panoramio,weather%7D.js
我的程序非常小,所以希望它可以很容易修复
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, GMClasses, GMMap,
GMDirection, GMDirectionVCL, GMMapVCL, Vcl.OleCtrls, SHDocVw, Vcl.ExtCtrls,
cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxStyles,
cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, cxNavigator, Data.DB,
cxDBData, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGridLevel, cxClasses, cxGridCustomView, cxGrid, Data.Win.ADODB;
type
TForm1 = class(TForm)
GMDirection1: TGMDirection;
GMMap1: TGMMap;
Panel1: TPanel;
Button1: TButton;
ListBox1: TListBox;
Edit2: TEdit;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery1Destination: TWideStringField;
WebBrowser1: TWebBrowser;
Panel2: TPanel;
Memo1: TMemo;
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
DataSource1: TDataSource;
cxGrid1DBTableView1Destination: TcxGridDBColumn;
Edit1: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses GMFunctionsVCL,GMConstants;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var a,i,j,km : integer;
begin
if ADOQuery1.Active then ADOQuery1.Close;
ADOQuery1.Open;
Edit1.Text:=inttostr(AdoQuery1.RecordCount);
ADOQuery1.First;
for a := 1 to ADOQuery1.RecordCount do
begin
ListBox1.Items.Delimiter:='-';
ListBox1.Items.StrictDelimiter:=true;
ListBox1.Items.DelimitedText:=ADOQuery1Destination.Value;
// first clear direction result , waypoints
if GMDirection1.DirectionsRequest.WaypointsList.Count <> 0 then
GMDirection1.DirectionsRequest.WaypointsList.Clear;
if GMDirection1.Count <> 0 then
for i := 0 to GMDirection1.Count-1 do
GMDirection1.Delete(i);
// igy jo a torles...ha nagyon gyorsan klikelltem akkor hibat csinalt...majd lehet progilag lassitanom kell kurva elet...
// de ahogy nezem meg a terkepet is odatudom savelni melle eppen ha nagyon akarom....
// ha 2 pont van akkor csak origin destination
// ha tobb pont van, a megalokat ugy hivjak hogy waypoint :)
GMDirection1.DirectionsRequest.Origin.Address:=ListBox1.Items[0]+', Serbia';
GMDirection1.DirectionsRequest.Destination.Address:=ListBox1.Items[ListBox1.Count-1]+', Serbia';
// if there are more then 2 addresses then the others are added in between as waypoints
if ListBox1.Count > 2 then
begin
for i := 1 to ListBox1.Count-1 do
GMDirection1.DirectionsRequest.WaypointsList.Add.Location.Address:=ListBox1.Items[i]+', Serbia';
for i := 0 to GMDirection1.DirectionsRequest.WaypointsList.Count-1 do
begin
GMDirection1.DirectionsRequest.Waypoints[i].StopOver:=true;
end;
end;
GMDirection1.Execute;
km:=0;
with GMDirection1.DirectionsResult[0] do
begin
if TTransform.DirectionsStatusToStr(Status) = 'dsOK' then
begin
for j := 0 to Routes[0].CountLeg - 1 do
km:=km+Routes[0].Leg[j].Distance.Value;
end
end;
km:=km div 1000;
Memo1.Lines.Add(inttostr(km));
ListBox1.Items.Clear;
ADOQuery1.Next;
sleep(100);
end;
Edit3.Text:=inttostr(Memo1.Lines.Count);
end;
procedure TForm1.GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
begin
if First then GMMap1.DoMap;
end;
end.
表单只有基本的GMDirection和GMMap,Webbrowser。正如我之前所说,如果我通过在每次查询睡眠(800)之后等待来引入严重的速度限制,它总是完成而没有错误。 但是,如果我没有睡觉就运行它...它设法做7-8结果......然后我得到这个错误:
请帮我把它带走
谢谢!