How to show Google Maps Alternative Routes on FNC Map

Hi, I am currently moving a project from WebGMaps to FNCMaps. I am able to show the map and a calculated route (A to B), but I am not able to establish how to show alternative routes. - do you have an example at all please..?

Reviewing FAQs I have established that you have to link a RouteCalculator to the FNCMap and set the option to retrieve alternativeroutes. I also noted that the routes then have to be inspected via the "ARequest.Items" object returned with "RouteCalcGetRouteDirections".

In my example, I have done this, and I can see this object (items) contains 3 routes, but the map displays the first route by default. I want to offer a list of the alternative route options (items array) and when clicked, show this route on the FNCMap. Is there a way to tell the map which route to display (1, 2 or 3), or alternatively replace the route when selected etc...?

If I need to ignore default drawing (by FNC Map) and draw routes manually (from items array), do you have any examples of how I could do this please from the alternatives routes collection..?

Many thanks in advance.

The option to include alternative routes is only to include them in the calculations, not to display them. You need to manually display them. Below is a piece of code to use:

    for I := 0 to ARequest.Items.Count - 1 do
      it := ARequest.Items[I];
      arr := it.Coordinates.ToArray;
      with m.AddPolyline(arr) do
        StrokeColor := gcDarkgoldenrod;
        StrokeWidth := 4;

Thanks Pieter,
The code snip has really helped. I have managed to use this to plot the alternatives to the map.
In follow up, could you confirm the 2 queries below if possible please; thanks.

  1. My testing shows that (if enough exist), I seem to get 3 alternative routes. Route 1 of the alternatives also seems to be the main route (default route) that would be plotted without alternatives. - is my assumption correct that you get max of 3, and route 1 is the default..?

  2. In the context of the above; is it possible to stop the "default" plot (blue line), so that I can plot all three routes myself using your code snip...? (My rationale is that I will then highlight the route or "alternative" route that the user has selected from a drop-down list). Currently, the default map route is being drawn in blue.

Many thanks in advance.

  1. Please take a look at the Directions demo, which has a shared UBL.pas layer that contains the code to handle multiple directions. In this sample, the last item is marked in blue, the others are marked in gold/yellow. The amount of alternatives depends on the start & destination & the service. It could be that there are no alternative routes, or there are more than three.

  2. When connected & active the route calculator plots the route & adds start & end markers automatically. You could clear them, but then you need to make sure you manually add the necessary information such as start & end markers. You can take a look at the code inside the method RouteCalculatorPlotRoute in FMX.TMSFNCMaps.pas

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