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
FstartAdres.Longitude
. Sure only oneARequest.Items
always exist? Why not asking TMS directly for support?Showmessage(Alongitude)
andshowmessage(Alatitude)
in theGetgeocoding
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.TMSFNCGeocoding.GetGeocoding()
runs asynchronously, in which case you would be trying to use yourALatitude
/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.