Zoom to bounds only works when run a second time

Hi

I can't get ZoomtoBounds to run unless I add a showmessage as per below.
It restrieves coordinates from a table, then adds markers. That all works fine but it won't ZoomtoBounds.
I'm sure I had it working to start with but can't work out whet I;ve done.
Thanks
Andy

procedure TForm1.Button3Click(Sender: TObject);
var
b: TTMSFNCMapsBoundsRec;
fltNorth, fltSouth, fltWest, fltEast : double ;
i : smallInt ;
begin
i := 0 ;

DBGrid1.DataSource := nil ;

FDMemTable1.IndexName := 'LONGDITUDE' ;
FDMemTable1.First ;
fltWest := FDMemTable1.FieldByName('LONGDITUDE').AsFloat ;
FDMemTable1.Last ;
fltEast := FDMemTable1.FieldByName('LONGDITUDE').AsFloat ;

FDMemTable1.IndexName := 'LATITUDE' ;
FDMemTable1.First ;
fltNorth := FDMemTable1.FieldByName('LATITUDE').AsFloat ;
FDMemTable1.Last ;
fltSouth := FDMemTable1.FieldByName('LATITUDE').AsFloat ;

TMSFNCMaps1.LocalFileAccess := True ;
TMSFNCMaps1.Markers.Clear ;

// showmessage('Map Ready');

TMSFNCMaps1.BeginUpdate;

FDMemTable1.First ;

while not FDMemTable1.Eof do
begin
fCoords.Longitude := FDMemTable1.FieldByName('LONGDITUDE').AsFloat ;
fCoords.Latitude := FDMemTable1.FieldByName('LATITUDE').AsFloat ;
TMSFNCMaps1.Addmarker(fCoords, IntToStr(i) + ': '+'16') ;

TMSFNCMaps1.Markers.Items[i].Longitude := fcoords.Longitude ;
TMSFNCMaps1.Markers.Items[i].Latitude := fcoords.Latitude ;
// TMSFNCMaps1.Markers.Items[i].Title := IntToStr(i) + ': '+'16';
TMSFNCMaps1.Markers.Items[i].IconURL := 'C:\Data\Development\Icons\New Buttons 2019\Invoice40.png' ;

inc(i);

FDMemTable1.Next ;

end;

TMSFNCMaps1.EndUpdate ;
//TMSFNCMaps1.SetCenterCoordinate( fCoords );

b.NorthEast.Latitude := fltNorth;
b.NorthEast.Longitude := fltEast;
b.SouthWest.Latitude := fltSouth;
b.SouthWest.Longitude := fltWest;

TMSFNCMaps1.ZoomToBounds(b);

DBGrid1.DataSource := DataSource1;

end;

Hi,

It could be possible that the map is still loading therefore the JavaScript cannot be accessed yet. to make sure that the map is initialized, please await the OnMapInitialized event and then call ZoomToBounds

Sounds like a plan. How do I tell it to wait ?
Thanks
Andy

Hi Peter
I found out what kills it - this line -

TMSFNCMaps1.LocalFileAccess := True ;
If I take it out it works fine. Is there another way to turn this one ?or does it need to be ay a specific point ?

Setting the map enabled = false and issuing the line before making it enabled seems to fix it.

Hi,

Thanks for this information, that's strange however, we'll look into it. It's good that you found a workaround for now.