0

The idea is to get the coordinates of an address and be able to use these coordinates in the code that follows. This should all happen in one function. Now, converting the address to coordinates is not the problem. this just works. Only when I assign the longitude and latitude to a variable it does not give any values when I call the variables later in the function. TTMSFNCGeoCoding is used for this.

    Function TestFunction:Boolean;
    var
    ALongitude,ALatitude : string;
    FstartAdres : TTMSFNCMapsCoordinateRec;
    begin
    
    TMSFNCGeocoding1.GetGeocoding('New York',
    procedure(const ARequest : TTMSFNCGeocodingRequest;
     const ARequestResult : TTMSFNCCloudBaseRequestResult)
     begin
     FStartAdres := ARequest.Items[0].Coordinate.ToRec;
     ALongitude := FloatToStr(FstartAdres.Longitude);
     ALatitude := FloatToStr(FStartAdres.Latitude);
     end);
    
//for example i want to show the data 
    showmessage(ALongitude); //message is empty
    showmessage(ALatitude);//message is empty
    end;

if I have forgotten important information let me know

  • Is the callback ever executed? Because untouched Strings remain empty, of course. Set a breakpoint to inspect the content of `FstartAdres.Longitude`. Sure only one `ARequest.Items` always exist? Why not asking TMS directly for support? – AmigoJack Dec 07 '22 at 15:45
  • @AmigoJack if I set the `Showmessage(Alongitude)` and `showmessage(Alatitude)` in the `Getgeocoding` procedure the message gives coordinates. so yes there is an item. And I didn't think of asking TMS directly. Thanks for noticing that! I will ask them also. – aaron versfeld Dec 07 '22 at 15:53
  • @aaronversfeld Most likely, `TMSFNCGeocoding.GetGeocoding()` runs *asynchronously*, in which case you would be trying to use your `ALatitude`/`ALongitude` variables *before* your callback has actually been called. That is why you are not seeing the values in your function. So, trying to do everything in one function simply isn't going to work, you need to break up your code logic so that your function can finish its work after the callback has actually been called. – Remy Lebeau Jan 23 '23 at 21:14

0 Answers0