app.component.ts
конструктор (платформа: Platform, statusBar: StatusBar, splashScreen: SplashScreen, частный backgroundMode: BackgroundMode, publi c cs: CustomService) {platform.ready (). Then ( () => {
statusBar.styleDefault();
splashScreen.hide();
this.backgroundMode.enable();
this.cs.startBackgroundLocation();
});
}
cucstomservice.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;
});
});