batch getgeocoding

Hi
I'm just playing with the Maps demos and struggling to work out how to send a batch of addresses to a TMSFNCGeocoding1 component. I've tried processing a list by issuing GetGeocoding for each address but it goes too fast and unless I put in a showmessage after each one, it doesn't return any co-ordinates. I'm using Bin for the lookup if makes any difference. There seems to be a way to send all the the requests in one go and handle the returned values but I can't seem to work out wgether I should be using - TMSFNCGeocoding1.AddRequest() and if so what to write into it.
I'm going to either process a table, query or stringlist.
An example would be really handy.
Thanks
Andy

Hi,

Unfortunately batch requests are currently not supported in TTMSFNCGeocoding.
Please note that requests are handled asynchronously which means if you process a lot of requests at the same time they are also executed at the same time. Usually the geocoding service will only accept a limited amount of requests at the same time.

Alternatively you can execute a single request and then wait for the OnGetGeocoding event or the callback to be triggered before executing the next request.

Thanks for the reply. I have pasted my code below as I can't work out how to handle the callback or the onGetgeocoding. I don't seem to be able to make the calls to GetGeocoding to wait for me to handle the data returned. Do you have an example ?
Thanks
Andy

Here are two examples for both methods.

  • GetGeocoding Callback
procedure TForm1.Button1Click(Sender: TObject);
begin
  //Execute frist request
  TMSFNCGeocoding1.GetGeocoding(strAddress,
        procedure(const ARequest: TTMSFNCGeocodingRequest; const ARequestResult: TTMSFNCCloudBaseRequestResult)
        begin
          TTMSFNCUtils.Log('geocoding callback: ' + FloatToStr(ARequest.Items[0].Coordinate.Latitude));
          //Execute next request
        end);
end;
  • GetGeocoding OnGetGeocoding event
procedure TForm1.Button1Click(Sender: TObject);
begin
  //Execute frist request
  TMSFNCGeocoding1.GetGeocoding(strAddress);
end;

procedure TForm1.TMSFNCGeocoding1GetGeocoding(Sender: TObject;
  const ARequest: TTMSFNCGeocodingRequest;
  const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
  TTMSFNCUtils.Log('geocoding event: ' + FloatToStr(ARequest.Items[0].Coordinate.Latitude));
  //Execute next request
end;

Thanks

I also found a really good example from, Peter which has worked well. I'm just looking at ZoomtoBounds, I assume I need to supply the function with NorthEast and SouthWest co-ordinates and there isn't a method for the component to calculate it?

By the way, this works miles better than the Dev express map. (although their other products are very good.)

You can indeed use NorthEast and SoutWhest coordinates with the ZoomToBounds function, but it also accepts an array of coordinates for which the bounds will be automatically calculated.

Thank you for your positive comment!

Thanks. How do I send an array of co-ordinates ?
Andy

This is an example of how you can use an array of coordinates with ZoomToBounds:

procedure TForm1.Button2Click(Sender: TObject);
var
  ar: TTMSFNCMapsCoordinateRecArray;
begin
  SetLength(ar, 3);
  ar[0].Longitude := 0;
  ar[0].Latitude := 50;
  ar[1].Longitude := 10;
  ar[1].Latitude := 50;
  ar[2].Longitude := 15;
  ar[2].Latitude := 55;
  TMSFNCMaps1.ZoomToBounds(ar);
end;