0

On my main form, I have a list of customers. I can select a customer and then click a button that loads a GMMap and displays some information about that customer and shows the customers location.

This works great the first time it is called but produces an exception on subsequent calls. In the FormShow of the map form is the following ...

procedure TfrmMap.FormShow(Sender: TObject);
begin    
  if not gmMap.Active then
  begin
    gmMap.Active := true;
  end;

  gmMap.RequiredProp.Center.Lat := customer.Lat;
  gmMap.RequiredProp.Center.Lng := customer.Lng;


  //Either of the following cause the exception after the first call success
  gmMap.PanTo(gmMap.RequiredProp.Center.Lat, gmMap.RequiredProp.Center.Lng);
  gmMap.SetCenter(gmMap.RequiredProp.Center.Lat, gmMap.RequiredProp.Center.Lng);
end;

procedure TfrmMap.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  gmMap.Active := false;
end;

When I call either gmMap.SetCenter or gmMap.PanTo for the second time I get an exception ...

Página inicial aun no cargada (Initial page not yet loaded)

However, moving the setCenter call to 'AfterPageLoaded' event produces a further exception (An error has occured in a script on this page).

My question is. How can I correctly reset a GMMap's center to display a new customer location each time I call my map form, from my main form.

Delphi XE

GMLIB 1.5.5

Johnny
  • 539
  • 8
  • 20
  • Do your stuff in the `AfterPageLoaded` event handler. – Victoria Jul 10 '18 at 09:25
  • @Victoria Thanks. I had tried moving things to that event but got scripting errors. I will try this again though. – Johnny Jul 10 '18 at 09:34
  • Updating the requiredProp.center and calling gmMap.setCenter in the AfterPageLoaded event displays 'a scripting error has occured' message (Code 80020101). I even tried setting all other events of the gmMap to nil and then reassigning them after the AfterPageLoadedevent had completed, but I got the same scripting error. – Johnny Jul 10 '18 at 09:56

1 Answers1

0

I found the solution.

I do not need to call setCenter at all. I just need to set the RequiredProps.Center.Lat and Lng and that is it.

Johnny
  • 539
  • 8
  • 20