TMS FNC Route Calculator — Guides
Route building
Users build routes by clicking waypoints on the map. The route calculator draws polyline segments between points and fires OnCalculateRoute when the route is updated.
Undo and redo
Call Undo and Redo to step through the route edit history. The HistoryManager property exposes the full undo/redo stack.
GPX import and export
Export the current route to a GPX file by calling SaveToGPX. Load a previously saved route by calling LoadFromGPX.
Route options
Configure polyline appearance, routing mode (driving, walking, cycling), and directions integration via the Options property (TTMSFNCRouteCalculatorOptions).
Service backends
Set the Service property to select the routing engine used to calculate routes. TTMSFNCRouteCalculatorService supports csAzure, csBing, csGoogle (the default), csHere, csMapBox, csOpenRouteService, and csGeoApify.
Reach for a specific backend based on coverage and pricing: csOpenRouteService is a good option for an open-data routing engine without a commercial API key requirement for low volumes, and csGeoApify bundles routing with the rest of the Geoapify location platform if the application already uses its geocoding or places APIs. Both are selected the same way as any other backend — set Service and APIKey before calling CalculateRoute.
procedure TForm1.SelectOpenRouteServiceProvider;
begin
{ Route calculation through the open-data OpenRouteService backend. }
TMSFNCRouteCalculator1.Service := csOpenRouteService;
TMSFNCRouteCalculator1.APIKey := 'YOUR-OPENROUTESERVICE-API-KEY';
end;
procedure TForm1.SelectGeoApifyProvider;
begin
{ Route calculation through the Geoapify backend, useful when the
application already uses Geoapify for geocoding or places. }
TMSFNCRouteCalculator1.Service := csGeoApify;
TMSFNCRouteCalculator1.APIKey := 'YOUR-GEOAPIFY-API-KEY';
end;
Locale options
Options.Locale sends a locale string with every service request, and Options.LocaleMode (TTMSFNCMapsLocaleMode) controls how that string is interpreted before it is sent: mlmDefault passes the locale through unchanged, mlmCountry extracts only the country portion (e.g. FR from fr-FR), and mlmLanguage extracts only the language portion (e.g. fr from fr-FR). Use mlmCountry or mlmLanguage when the selected backend expects a narrower locale format than a full culture string.
procedure TForm1.UseFullLocale;
begin
{ Send the full locale string as-is to the service (e.g. "fr-FR"). }
TMSFNCRouteCalculator1.Options.Locale := 'fr-FR';
TMSFNCRouteCalculator1.Options.LocaleMode := mlmDefault;
end;
procedure TForm1.UseCountryFromLocale;
begin
{ Extract only the country part of the locale string ("FR") before
sending it, for backends that expect a country code. }
TMSFNCRouteCalculator1.Options.Locale := 'fr-FR';
TMSFNCRouteCalculator1.Options.LocaleMode := mlmCountry;
end;
procedure TForm1.UseLanguageFromLocale;
begin
{ Extract only the language part of the locale string ("fr") before
sending it, for backends that expect a language code. }
TMSFNCRouteCalculator1.Options.Locale := 'fr-FR';
TMSFNCRouteCalculator1.Options.LocaleMode := mlmLanguage;
end;
Segment details and GPX export
Every TTMSFNCRouteCalculatorSegment exposes the resolved StartAddress and EndAddress for that segment (Google), which is useful for display when the route itself was built from coordinates or waypoints rather than typed addresses.
A calculated route can also be exported as a GPX track for use in mapping and navigation tools outside the application. SaveToGPXFile, SaveToGPXStream, and SaveToGPXText each accept a TTMSFNCRouteCalculatorRoute and an optional TTMSFNCMapsGPXMetaData, and only differ in the destination — a file path, an open stream, or an in-memory string. Overloads that accept a raw coordinate array directly are also available for exporting route data that was not produced by CalculateRoute. Passing AMetaData sets the GPX author and track information; omitting it writes default metadata.
procedure TForm1.TMSFNCRouteCalculator1CalculateRoute(Sender: TObject;
const ARoute: TTMSFNCRouteCalculatorRoute);
var
Segment: TTMSFNCRouteCalculatorSegment;
I: Integer;
MetaData: TTMSFNCMapsGPXMetaData;
begin
{ Google reports the resolved street address for the start and end of
each segment, useful when the route was built from coordinates or
waypoints and the human-readable address is still needed for display. }
for I := 0 to ARoute.Segments.Count - 1 do
begin
Segment := ARoute.Segments[I];
{ Segment.StartAddress and Segment.EndAddress hold the resolved addresses. }
end;
MetaData.AuthorName := 'My Application';
MetaData.TrackName := ARoute.RouteName;
MetaData.TrackType := 'driving';
{ Export the route as GPX, either straight to a file, ... }
TMSFNCRouteCalculator1.SaveToGPXFile(ARoute, 'route.gpx', MetaData);
{ ... or as text for further processing / upload without touching disk. }
ShowMessage(TMSFNCRouteCalculator1.SaveToGPXText(ARoute, MetaData));
end;
procedure TForm1.ExportRouteToStream(AStream: TStream;
ARoute: TTMSFNCRouteCalculatorRoute);
begin
{ A GPX stream export is also available for cases that write to a
TFileStream, TMemoryStream, or a custom destination. }
TMSFNCRouteCalculator1.SaveToGPXStream(ARoute, AStream);
end;