How do I access Location Elevation through the TTMSFNCElevation component?
I dont seem to find the GetElevation() function.
With this code you should be able to achieve this:
var
coord: TTMSFNCMapsCoordinateRec;
begin
TMSFNCElevation1.GetElevationResult(coord,
procedure(const AResult: TTMSFNCElevationRequest)
var
el: Single;
begin
if AResult.Items.Count > 0 then
begin
//elevation
el := AResult.Items[0].Elevation;
end;
end);
Thanks for that, can you perhaps provide code in C++ also?
Hi,
I am also having difficulty implementing code to get the elevation for map coordinates. I have tried implementing your suggested code Pieter, but cannot get it to retrieve coordinates. My code is:
var
Lat,Lng : double;
Elev : single;
ACoord : TTMSFNCMapsCoordinateRec;
begin
...
ACoord := CreateCoordinate(Lat,Lng)
Elev := 0;
FNCElevation.GetElevationResult(ACoord,
procedure(const AResult: TTMSFNCElevationRequest)
begin
if AResult.Items.Count > 0 then
Elev := AResult.Items[0].Elevation;
end);
...
end;
I then try to use the value assigned to Elev after your nested GetElevationResult procedure, but it always returns with a 0.
This code is actually in a loop with other code (...) which is creating additional information for each coordinate as well as the elevation. I am assigning valid Lat and Lng before the code example here.
If I examine values in debug mode the GetElevationResult procedure is called, and Elev gets elevation values, but these values are not available after the call is completed, Elev is a 0.
Any suggestions why I am not getting any values for Elev outside your nested procedure? I am a newbie to using nested procedures, keen to learn what I am doing wrong.
Jonathan
Hi,
The anonymous callback is asynchronous, so the callback will be triggered at a later time, after the method has finished, that's why Elev is 0 at the end of the method.
Thanks Pieter
I have now changed my code to
- build up a TTMSFNCMapsCoordinateRecArray (ACoordRecArray) of all coordinates (over 800 of them)
- use .GetElevationResult(ACoordRecArray,nil) to request elevations for all these coordinates at once
- wait for the OnGetElevation event which signals when all the elevation data is ready
- then extract the elevations from the .ElevationData array (provided as part of the TTMSFNCElevation component). I use the .Elevation value that comes with each TTMSFNCMapsCoordinateRec in this array of results.
This works well, and I am able to get lots of elevations.
Thanks for your help. I would be interested if anyone has found better ways to do this.
Jonathan