Open chris248-git opened 4 years ago
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.
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.
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?
@explooosion Can you show an example for selecting an alternate route using the draggable option ?
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
Hi All, please help on this issue. i need show alternative routes on map like google map
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.