您好我目前正在使用angular-google-maps 使用标记构建地图并需要检索地图标记数组:
<agm-map [latitude]="lat" [longitude]="lng" [zoom]="14" (mapReady)="isMapReady($event)" (boundsChange)="onMapBoundsChange($event)">
<div>
<ng-container *ngFor="let activity of activityCollection; let i = index;">
<agm-marker [latitude]="activity.geoPoint.latitude" [longitude]="activity.geoPoint.longitude" [visible]="checkIfMarkerVisible(i)"></agm-marker>
</ng-container>
</div>
</agm-map>
我知道我可以手动添加标记,但我希望有一种方法可以使用AGM标记检索此数组。
addMarker(map) {
this.markerArray = [];
for (let i = 0; i < this.activityCollection.length; i++) {
let myLatlng = new google.maps.LatLng(this.activityCollection[i].geoPoint.latitude, this.activityCollection[i].geoPoint.longitude);
let marker = new google.maps.Marker({
map: map,
position: myLatlng
});
this.markerArray.push(marker);
marker.setMap(map);
bounds.extend(new google.maps.LatLng(visibleFilteredActivities[i].geoPoint.latitude, visibleFilteredActivities[i].geoPoint.longitude));
}
}