Remove old markers ionic 3 firebase


I’m update position in firebase of user with this code

  ionViewDidLoad() {

  getMyPosition() {
    let watch = this.geolocation.watchPosition();
    watch.subscribe((result) => { 
      this.positionTruck = new google.maps.LatLng(result.coords.latitude, result.coords.longitude);
      const mapOptions = {
        zoom: 18,
        center: this.positionTruck,
        disableDefaultUI: true
      } = new google.maps.Map(document.getElementById('map'), mapOptions);
      let truck = { latitude: result.coords.latitude, longitude: result.coords.longitude };
      this.truckService.update(this.truck.key, truck); 

but the markers are lagging behind

how to remove this markers ?


While this answer does not directly fix your issue, what you are doing with Firebase may not be ideal on it’s own. For geolocation related tasks there is an additional tool called “GeoFire” which is outstanding and helps with realtime Firebase geolocation quieries, I would highly suggest looking into this especially if you plan to increase your query amounts: