0

I've written a little test program to parse destinations from my Vehicle Registration program, and compare user entered km with google km . My problem is if I don't use sleep(800) after each GMDirection1.Execute; I get this exact error every time : https://maps.gstatic.com/cat_js/intl/de_de/mapfiles/api-3/15/11/%7Bmain,geometry,panoramio,weather%7D.js

my program is very small, so hopefully It can be fixed very easily

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.

The form has only the basic GMDirection and GMMap, Webbrowser . As I said before if I introduce a serious speed limit by waiting after each query sleep(800) it always completes without errors. But if I run it without sleep ...it manages to do 7-8 results...then I get this error :

https://maps.gstatic.com/cat_js/intl/de_de/mapfiles/api-3/15/11/%7Bmain,geometry,panoramio,weather%7D.js

Please help me make it go away

Thank you!

RRUZ
  • 134,889
  • 20
  • 356
  • 483
user1937012
  • 1,031
  • 11
  • 20
  • Google Maps API have a limit of request (if you don't pay and get a key). This limit is 8 consecutive requests. After this 8 consecutive requests, you need to wait about 1 sec for the next requests until, I think, 250 requests. Isn't a GMLib limitation ;-) – cadetill Feb 12 '14 at 16:45
  • Thank you very much for your fast response. I think I will buy a key since it's not that much 5 eur per month, question is how do I use that key with GMLib ? – user1937012 Feb 17 '14 at 21:46
  • With the latest GMLib version you can specify a Google Maps key. You can download it from [SVN repository](http://code.google.com/p/gmlibrary/source/checkout) – cadetill Mar 02 '14 at 19:07

0 Answers0