1

I have an application that has a button that, when clicked, runs a query, then reads through the dataset and adds markers to a TGMMap/TGMMarker corresponding to the values read (it also uses a TGMGeoCode to geocode address values, if that matters). The first time that the button is clicked, the correct number (10) of markers is always placed, but if I click the button again right after the points are shown, a random number of markers is drawn (sometime 3, sometimes 1, sometimes 5, etc.). However, if I wait for some time (about 15-20 seconds) before clicking the button again, the correct number of points is always drawn, so I'm sure that it's some kind of timing issue where the DOM is maybe not fully built or some script is still executing or ??? Is there some kind of status flag that I can check to make sure that the map is ready to accept new markers, or is there some kind of ProcessMessage loop that I need to implement or ??

The code basically works like this every time the button is clicked:

  dataSet.Active := false;
  dataset.Active := true;
  Marker1.Clear();
  while (dataset.Eof=false) do
  begin
    fGeoCoder.Geocode(address);
    // Use first GeoCode result??
    if (fGeoCoder.GeoStatus = gsOK) and (fGeoCoder.Count > 0) then
    begin
      geoResult := fGeoCoder.GeoResult[0];
      lat := geoResult.Geometry.Location.Lat;
      lng := geoResult.Geometry.Location.Lng;

      marker := Marker1.Add(lat, lng);
    end;
    dataset.Next();
  end;

Thanks in advance for any help you can provide.

1 Answers1

0

This is a Google Maps API limitation, it isn't a GMLib problem. If you don't want wait, you need to pay for Google Maps API access. If not, you can check the Geocoding status (GeoStatus) and, if it is different of gsOK, wait some seconds and send the same request

cadetill
  • 1,552
  • 16
  • 24
  • 1
    Yes, thank you cadetill, I didn't realize that there were limitations on the geocoding API. For others that are interested, see developers.google.com/maps/documentation/business/articles/… for details, basically you are allowed 10 geocode requests per second. Some sample Delphi code to process those requests: i := 1; while (fGeoCoder.GeoStatus = gsOVER_QUERY_LIMIT) and (i<=3) do begin Sleep(2000); fGeoCoder.Geocode(address); Inc(i); end; – Andrew Clark Dec 26 '15 at 01:29