Remove old markers ionic 3 firebase


#1

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

  ionViewDidLoad() {
    this.getMyPosition();
  }

  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
      }
      this.map = new google.maps.Map(document.getElementById('map'), mapOptions);
      this.truckMarker(this.positionTruck);
      this.markerDumps();
      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 ?


#2

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: