Route between two points

Hi, I am evaluating the WebMap component and so far have located two places and add markers for them. Now I want to "draw" or make the route between both as google maps does.

I am using waypoints ( seen in demo ) but cant figure out what parameters should have or how to invoke them .

Can anyone give me some idea ?

Thanks so much.

You can use the overload of WebGMaps.RenderDirections() that has the parameter to add the list of waypoints, which is a TStringList of addresses as waypoints between start and end address:


    function RenderDirections(Origin, Destination: string;
      TravelMode: TTravelMode = tmDriving; AvoidHighways: Boolean = false;
      AvoidTolls: Boolean = false; WayPoints: TStringList = nil;
      OptimizeWayPoints: Boolean = false; RouteColor: TColor = clNone): Boolean; overload;

Hi Bruno, thanks for answer.
I dont know how to overload that function, where must I define that ?

This is my code.. could you tell me if it is correct ?

    WebGMapsGeocoding.Address := cDirEmpresa;

    if WebGMapsGeocoding.LaunchGeocoding = erok then
    begin
        webmap.MapOptions.DefaultLatitude  := WebGMapsGeocoding.ResultLatitude;
        webmap.MapOptions.DefaultLongitude := WebGMapsGeocoding.ResultLongitude;

        // add marker
        webmap.Markers.Add( WebGMapsGeocoding.ResultLatitude,    WebGMapsGeocoding.ResultLongitude, cDirEmpresa );
        WayPoints.Add( cDirEmpresa );

    end;

    WebGMapsGeocoding.Address := cDirCliente;
    if WebGMapsGeocoding.LaunchGeocoding = erok then
    begin

        webmap.MapOptions.DefaultLatitude  := WebGMapsGeocoding.ResultLatitude;
        webmap.MapOptions.DefaultLongitude := WebGMapsGeocoding.ResultLongitude;

        // add marker
        webmap.Markers.Add( WebGMapsGeocoding.ResultLatitude, WebGMapsGeocoding.ResultLongitude, cDirCliente );
        WayPoints.Add( cDirCliente );

        webmap.MapOptions.ZoomMap := 14;
        webmap.Launch;

        try
            webmap.GetDirections( cDirEmpresa, cDirCliente , True, tmDriving, usMetric, lnSpanish, True, True, WayPoints , True );
        finally
            WayPoints.Free;
        end;

cDirEmpresa and cDirCliente are strings with the two address I wanto to draw the route..

Many many thanks !!

Hi,


The WayPoints object should indeed be used as a parameter in the GetDirections call.
You can have a look at the WebGMapsDirections demo aplication for a full working example.

Hi Bar, as you can see in my code I have the WayPoint string in the parameters.

The demo it nos working for me because its says I am not the owner of the map.

Any help would be very appreciate.

Regards

We are not aware of any issues with the WebGMapsDirections demo.
The only thing that is required to make the app function correctly is a valid API Key value assigned to TWebGMaps.APIKey.


If the problem persists, please provide an exact description of what is going wrong and of the error message you are seeing so I can further investigate this.
Hi thanks for the answer. I am trying to test the demo and get the error showed in the image.

I've got a new api from google and assigned to the webmap component, and still have the error.

https://ibb.co/dFStV0

What can I do ??
Hi, I have changed all the code with the help of one of your youtube's videos and now its working.

Thanks a lot !!

Thanks for informing

Hi, Bruno, just a "small" question.
It is possible to center the map again after searching two address and draw a route between them ?

Thanksss !!!

You can move the center position of the map programmatically by calling

WebGMaps.MapPanTo(lat,lon)
Perfect..
Thanks !!!!