Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative routes are not displayed #81

Open
chris248-git opened this issue Dec 25, 2019 · 5 comments
Open

Alternative routes are not displayed #81

chris248-git opened this issue Dec 25, 2019 · 5 comments

Comments

@chris248-git
Copy link

Since the directive is providing the option "provideRouteAlternatives" it does not display the alternative routes.

Within the code of the directive only the first route is called
--> see line 180: const _route = response.routes[0].legs[0];

According to the directions api description, google is providing an array of alternative routes.

@explooosion explooosion added the bug Indicates an unexpected problem or unintended behavior label Jan 5, 2020
@explooosion
Copy link
Owner

explooosion commented Jan 5, 2020

Hi @chris248-git

According to the Directions Requests, alternative routes won't show at the same time.

If you want to get the result of alternative routes,
you can set [provideRouteAlternatives]="true" and use (onResponse) to listening the result.

Alternative routes response:

image

Or using the option panel :
<agm-map [latitude]="lat" [longitude]="lng">
  <agm-direction
   [origin]="origin"
   [destination]="destination"
   [provideRouteAlternatives]="true"
   (onResponse)="onResponse($event)"
   [panel]="myPanel"
   >
  </agm-direction>
</agm-map>
<div #myPanel></div>
  public lat = 24.799448;
  public lng = 120.979021;

  public origin: any = 'No. 1, Section 1, Taiwan Avenue, Central District, Taichung, Taiwan';
  public destination: any = 'No. 1 Guanqian Road, North District, Taichung City';

  public onResponse(event: any) {
    console.log(event);
    // You can do anything.
  }

Finally, the code in line 180 const _route = response.routes[0].legs[0]; won't affect alternative routes. Only pick up the origin's and destination's location and address.

@explooosion explooosion removed the bug Indicates an unexpected problem or unintended behavior label Jan 5, 2020
@chris24802
Copy link

Thanks a lot. I managed to draw also the alternative routes using a for loop in the onResponse method:

public onResponse(event: any) {
    let color: string[] = ['#FF6859', '#FFCF44', '#B15DFF']     

    for (let i = 0, len = event.routes.length; i < len; i++) {

      this.myDir[i] = new google.maps.DirectionsRenderer({
            map: this.thisMap,
            directions: event,
            routeIndex: i,
            polylineOptions: { strokeColor: color[i] }
        });
    }   
}

How can I remove this directions if I'd like to get a new destination?

@jnair-tsystems
Copy link

@explooosion Can you show an example for selecting an alternate route using the draggable option ?

@peploc-innocv
Copy link
Contributor

hi @chris248-git @chris24802,
can you post a most complete snippet of your alternative route implementation, especially how you achieve select the agm map component stored in "this.thisMap" and what's "this.myDir" and why you have to store the render.
Tnx in advance

@ashokpal100
Copy link

Hi All, please help on this issue. i need show alternative routes on map like google map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants