I'm trying to get waypoints in between my origin and destination address in Angular Google Maps. I have an arraywaypoints: any
and a method to add waypoints dynamically:
addWaypoint($event) { this.waypoints.push({ location: { lat: $event.geoLocation.latitude, lng: $event.geoLocation.longitude}, stopover: true }); console.log(this.waypoints); }
but those waypoints won't display on the map.
<agm-map [latitude]="lat" [longitude]="lng" [scrollwheel]="false" [zoom]="zoom">
<agm-marker *ngIf="!destination" [latitude]="lat" [longitude]="lng"></agm-marker>
<agm-direction *ngIf="destination" [origin]="origin" [destination]="destination" [waypoints]="waypoints">
</agm-direction>
</agm-map>
If I add waypoints static to the array, they will be shown:
addWaypoint($event) {
this.waypoints = [{
location: { lat: $event.geoLocation.latitude, lng: $event.geoLocation.longitude},
stopover: true
}];
console.log(this.waypoints);
}
The console output is in both cases the same:
Any suggestions? Thanks
Found a solution for this by using the spread operator:
this.waypoints = [...this.waypoints, ...[{
location: { lat: $event.geoLocation.latitude, lng: $event.geoLocation.longitude},
stopover: true
}]];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.