How to remove marker from Google map

Hi all, I just wanted to know how can I remove marker from google map.
The initial marker is the current position of the device itself and I’m working on tracking other users so need to remove the marker as soon as the admin selects another user to track.

 loadMap() {

    let mapOptions = {
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: false,
      streetViewControl: false,
      fullscreenControl: false
    }
    this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);

    this.geolocation.getCurrentPosition().then(pos => {
      let latLng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
      this.map.setCenter(latLng);
      this.map.setZoom(16);
      this.addMarker();
    }).catch((error) => {
      console.log('Error getting location', error);
    });

  }
  addMarker() {

    let marker = new google.maps.Marker({
      map: this.map,
      animation: google.maps.Animation.DROP,
      position: this.map.getCenter(),
    });
    this.markers.push(marker);
  }
}

@uddyvky

1 Like

Thanks for your reply but I wasn’t able to use it. Any other example… if you have??

it should work.Can you show the code which remove the old marker and draw new?

1 Like

Tried this solution and it worked well :
yourMarker.setMap(null);

It just makes it disappear. Thanks @mathewk :+1: