【发布时间】:2020-01-14 12:42:35
【问题描述】:
我正在尝试在 Angular 谷歌地图中获取我的起点和终点地址之间的航路点。
我有一个数组 waypoints: any
以及动态添加航点的方法:addWaypoint($event) {
this.waypoints.push({
location: { lat: $event.geoLocation.latitude, lng: $event.geoLocation.longitude},
stopover: true
});
console.log(this.waypoints);
}
但这些航点不会显示在地图上。
<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>
如果我将静态航点添加到数组中,它们将被显示:
addWaypoint($event) {
this.waypoints = [{
location: { lat: $event.geoLocation.latitude, lng: $event.geoLocation.longitude},
stopover: true
}];
console.log(this.waypoints);
}
两种情况下的控制台输出都是一样的:
有什么建议吗? 谢谢
【问题讨论】:
标签: angular typescript google-maps