I'm using Delphi 10.1 Berlin with GMLib 1.5.5 I can successfully display a map and populate Markers based on data from SQL dataset. But it can be rather slow to drop markers when the result sets of my queries become large. I think a lot of this is due to the overhead of GeoCoding addresses into LatLng.
I would like to GeoCode those address at the time of entry and store the Coordinates making it easier/quicker to display the markers. I wrote a function in my DataModule to GeoCode the address any time it changes (Before Post). But the routine 'hangs' as I don't believe the Map ever gets fully initialized (TGMMap.DoMap)
Here is my function:
procedure GeoCodeAddress(var coords: TLatLng; Address: String);
Var mMap : TGMMap;
mBrowser : TWebBrowser;
mGeoCoder : TGMGeoCode;
begin
mBrowser := TWebBrowser.Create(Nil);
mBrowser.Silent := True;
mMap := TGMMap.Create(Nil);
mMap.APIKey := GMapsAPIKey;
mMap.AfterPageLoaded := AfterPageLoaded;
mMap.WebBrowser := mBrowser;
mMap.Active := True;
//mMap.DoMap;
mGeoCoder := TGMGeoCode.Create(Nil);
mGeoCoder.Map := mMap;
mGeoCoder.Geocode(Address);
if mGeoCoder.GeoStatus = gsOK Then
Begin
Coords.Lat := mGeoCoder.GeoResult[0].Geometry.Location.Lat;
Coords.Lng := mGeoCoder.GeoResult[0].Geometry.Location.Lng;
End;
mGeoCoder.Free;
mMap.Free;
mBrowser.Free;
end;
procedure AfterPageLoaded(Sender: TObject; First: Boolean);
begin
if First then
TGMMap(Sender).DoMap;
end;
Thanks in advance for any suggestions.