首页 > 解决方案 > Ionic 3 背景位置不起作用。当APP进入后台时,后台位置不会在firebase上更新

问题描述

app.component.ts

构造函数(平台:平台,statusBar:StatusBar,splashScreen:SplashScreen,私有backgroundMode:BackgroundMode,公共cs:CustomService){platform.ready()。then(()=> {

  statusBar.styleDefault();
  splashScreen.hide();
  this.backgroundMode.enable();
  this.cs.startBackgroundLocation();
});

}


自定义服务.ts

    setInterval(()=>{
        this.count = this.count+1;
        firebase.database().ref('test/').set(this.count);
    },3000)

    let options = {
      frequency: 3000,
      enableHighAccuracy: true
    };

    this.backgroundGeolocation.watchLocationMode()

    this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {
      console.log(position);
      if(position){
        firebase.database().ref('testingData/')
        .set({
            lat:position.coords.latitude,
            lng:position.coords.longitude
        }).then(()=>{})
      }

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

标签: firebaseionic-frameworkgeolocationionic3

解决方案


推荐阅读