Getting GPX Data when using directions component

Hi,

unfortunately, I used the directions component to paint my way from Point A to Point B. Maybe it was because it is not possible to prevent the routes Component from showing a start and end Marker. anyway, I paint my route with the following Code inside the on getdirections event.

procedure TGCAxAJCSSmartRouteClient.DirectionsGetDirections(Sender: TObject; const ARequest: TTMSFNCDirectionsRequest;
  const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
  arr: TTMSFNCMapsCoordinateRecArray;
  arrA: TTMSFNCMapsCoordinateRecArrayArray;
  it: TTMSFNCDirectionsItem;
  i: Integer;
begin
  if ARequest.items.Count > 0 then
  begin
    TMSFNCMap.BeginUpdate;
    SetLength(arrA, ARequest.items.Count);
    for i := 0 to ARequest.items.Count - 1 do
    begin
      it := ARequest.items[i];
      arr := it.coordinates.ToArray;
      arrA[i] := arr;
      with TMSFNCMap.AddPolyline(arr) do
      begin
        if i = ARequest.items.Count - 1 then
          StrokeColor := gcDarkBlue
        else
          StrokeColor := gcDarkgoldenrod;
        StrokeWidth := 4;
        DataPointer := it;
      end;
    end;
    TMSFNCMap.EndUpdate;
  end
  else
    showmessage('Error');
end;

Is there a Way to export my Track as GPX File from Dircetions?

Hi,

You can use TMSFNCMaps to export a polyline to a GPX file.

Example:
TMSFNCMaps1.SaveToGPXFile(arr, "filename.gpx");

Where can I get the "arr" from? Arr is only available in "DirectionsGetDirections" function. Or is there a way to obtain the CoordianteRecArray afterward?

There are 2 options:

  • Get the coordinates from the polyline that was added to the map
  • Get the coordinates from the DirectionsRequests collection of the TTMSFNCDirections component
var
  arr: TTMSFNCMapsCoordinateRecArray;
begin
  arr := TMSFNCMaps1.Polylines[0].Coordinates.ToArray;
  //or
  arr := TMSFNCDirections1.DirectionsRequests[0].Items[0].Coordinates.ToArray;

  TMSFNCMaps1.SaveToGPXFile(arr, 'filename.gpx');
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.