Hi,
The Routes collection is filled up automatically, by calling RouteCalculator.CalculateRoute. You can check out the demo how the connection is made with the route calculator to plot routes via interaction.
RouteCalculator.zip (93.4 KB)
Alternatively, if you want to plot routes manually, you can call:
unit Unit21;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.TMSFNCTypes, FMX.TMSFNCUtils, FMX.TMSFNCGraphics, FMX.TMSFNCGraphicsTypes,
FMX.TMSFNCMapsCommonTypes, FMX.TMSFNCCustomComponent,
FMX.TMSFNCRouteCalculator, FMX.Controls.Presentation, FMX.StdCtrls,
FMX.TMSFNCCustomControl, FMX.TMSFNCWebBrowser, FMX.TMSFNCMaps;
type
TForm21 = class(TForm)
TMSFNCMaps1: TTMSFNCMaps;
Button1: TButton;
TMSFNCRouteCalculator1: TTMSFNCRouteCalculator;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form21: TForm21;
implementation
{$R *.fmx}
type
TTMSFNCMapsOpen = class(TTMSFNCMaps);
TTMSFNCRouteCalculatorOpen = class(TTMSFNCRouteCalculator);
procedure TForm21.Button1Click(Sender: TObject);
begin
TMSFNCRouteCalculator1.CalculateRoute(CreateCoordinate(40.391537, -104.681168), CreateCoordinate(32.253460, -110.911789),
procedure(const ARoute: TTMSFNCRouteCalculatorRoute)
begin
TMSFNCMaps1.ZoomToBounds(ARoute.Polyline);
end);
end;
procedure TForm21.FormCreate(Sender: TObject);
begin
TMSFNCRouteCalculator1.APIKey := 'MyAPIKey';
TMSFNCRouteCalculator1.Active := True;
TMSFNCMaps1.RouteCalculator := TMSFNCRouteCalculator1;
TTMSFNCRouteCalculatorOpen(TMSFNCRouteCalculator1).OnCalculateRouteInternal := TTMSFNCMapsOpen(TMSFNCMaps1).RouteCalculatorDoCalculateRoute;
TMSFNCMaps1.APIKey := TMSFNCRouteCalculator1.APIKey;
TMSFNCMaps1.Service := msGoogleMaps;
end;
end.
Note the assignment of the OnCalculatRouteInternal event, which actually should not be necessary, we have fixed this issue here internally, but it needs to be released. When the next version comes out, you can remove this line. When starting the application, clicking on the button, you will be able to calculate a route, and then manipulate it afterwards.