【问题标题】:Angular Google Maps waypoints don't display with dynamic waypoint array角度谷歌地图航点不显示动态航点数组
【发布时间】: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


    【解决方案1】:

    通过使用扩展运算符找到了解决方案:

    this.waypoints = [...this.waypoints, ...[{
            location: { lat: $event.geoLocation.latitude, lng: $event.geoLocation.longitude},
            stopover: true
        }]];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 2015-05-24
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多