在Cloud FireFrestore中保存坐标时出错

时间:2018-08-02 19:16:34

标签: javascript google-cloud-firestore

每次登录时,我都会激活此功能,目的是将我的同事的历史记录上传到Cloud Firestore,

start() { 

  let markes=[];
   this.backgroundGeolocation.isLocationEnabled()
   .then((activate) =>{
   //
   if(activate){
   let config = {
   desiredAccuracy: 0,
   stationaryRadius: 0,
   distanceFilter: 0,
   debug: false,
   interval: 0
 };
 //geolocation in the background      
 this.backgroundGeolocation
 .configure(config)
 .subscribe((location) => {

   let  _date: Date = new Date();
   let n: number = _date.getTime();
   n -= (_date.getTimezoneOffset() * 60 * 1000);
   let d: string = new Date(n).toISOString();

   this.zone.run(() => {
   this.lat=location.latitude;
   this.lng=location.longitude;
   });

      markes.push({
        latitud: this.lat,
        longitud: this.lng,
         date: d
      });

        this.db.collection("user").doc(this.nameUser).set({
          markes
        },{merge:true})
        .then(function() {})
        .catch(function(err) {
          console.log("Err" + err);
        });


   });

 // start recording location
  this.backgroundGeolocation.start();

 let options = {
   frequency: 300000,
   enableHighAccuracy: true,
   timeout:300000
 };
   //geolocation when the app is open
 this.watch = this.geolocation.watchPosition(options).filter((p: any) => 
 p.code === undefined)
 .subscribe((position: Geoposition) => {

 let  _date: Date = new Date();
   let n: number = _date.getTime();
   n -= (_date.getTimezoneOffset() * 60 * 1000);
   let d: string = new Date(n).toISOString();

     //
     markes.push({
          latitud:position.coords.latitude,
          longitud:position.coords.longitude,
          date:d
        });

        this.db.collection("user").doc(this.nameUser).set({
          markes
        },{merge:true})
        .then(function() {})
        .catch(function(err) {
          console.log("Err " + err);
        });
  });

  }else {
  this.backgroundGeolocation.showLocationSettings();
  }
}) 
}

但是当我注销然后再次登录时,所有上传的信息会自动被删除。

我该如何解决?我希望我的同窝人的历史保存至少两天,而又不会出现删除它们的问题,只需注销即可。

0 个答案:

没有答案