PageView not refreshing - Marker not removable - Google Map


#1

I’ve got a Google Map, where I display some markers.
I’ve a provider, where the whole process with initializing the google map etc. is in.
the provider is named google-maps.ts
and the page is named map.ts
There I’ve got an Array named ‘markers’, where I add the markers.

I’ve written three functions, which I call from outside, with an id. It also reaches inside of the if, but the marker isn’t removed from the map.

 activateMarker(id: number) {
    this.markers.forEach(marker => {
      if(marker.Id == id) {
        marker.setMap(this.map);
      }
    });
  }

  deactivateMarker(id: number) {
    console.log("deactivating");
    for (var i = 0; i < this.markers.length; i++) {
      if(this.markers[i].Id == id) {
        console.log("Im in");
        this.markers[i].setMap(null);
      }
    }
  }

First I thought, maybe the view is not reloaded.
So I also tried to directly write the code in the map.ts and access the google-maps.ts markers, where I also got into the if, but the markers still aren’t removed.

Then I thought, that it didn’t still reload, so I tested with the code below.

  reloadMap() {
    google.maps.event.trigger(this.map, 'resize');
  }

It doesn’t work though. Maybe you can help me.