I am trying to remove a particular marker from the map, for that, I've written the below
<button (click)="removeDriver(id)"></button>
removeDriver(userId) {
//remove from the array a particular user
this.places = this.places.filter((user) => {
return user.userId !== userId;
});
let currentDriverLocation;
//the array elements are updated now, and the markers should be plotted again
this.places.forEach((driver) => {
currentDriverLocation = new google.maps.LatLng(driver.currentLocation.lat, driver.currentLocation.long);
this.marker = new google.maps.Marker({ position: currentDriverLocation, map: this.map });
})
}
The array is updated with the new objects; however, no markers get deleted.
this.places array looks like the following:
[{"userId":"khfdg999","currentLocation":{"lat":59.02922, "lng":-12.3932}},
{"userId":"a85jfdo","currentLocation":{"lat":59.02922, "lng":-12.3932}}]