2017-11-20 110 views
10

Dodatek geolokalizacji tła dla jonowej nie aktualizuje się. Wymagana funkcjonalność to co 30 sekund zapytaj wtyczkę o wartość lng lng, jeśli jest dostępna. Problem polega na tym, że najpierw podaje mi wartości, a potem zatrzymuje się tło. Pierwszy plan jest w porządku, to naprawdę tło. Zasadniczo nie mogę wysłać żądań po pierwszym wysłaniu początkowym w tle.geolokalizacja jonowa 3 brak aktualizacji

gps.ts

startTracking() { 

    console.log('started tracking') 
    const config: BackgroundGeolocationConfig = { 
     desiredAccuracy: 10, 
     stationaryRadius: 20, 
     distanceFilter: 30, 
     debug: false, // enable this hear sounds for background-geolocation life-cycle. 
     stopOnTerminate: false 
    }; 

    this.backgroundGeolocation.configure(config) 
    .subscribe((location: BackgroundGeolocationResponse) => { 


     this.zone.run(() => { 
     this.lat = location.latitude 
     this.lng = location.longitude 
     this.bearing = location.bearing 
     this.speed = location.speed 
     this.accuracy = location.accuracy 
     this.timestamp = location.time 
     }) 


     this.backgroundGeolocation.finish(); // FOR IOS ONLY 
     this.backgroundGeolocation.stop() 

     }); 


    this.backgroundGeolocation.start(); 

    } 

sendGPS(){ 
this.optionsService.sendGPS(gpsData).subscribe(result => { 
      } 
     }) 
} 

stopTracking() { 

    this.sendGPS() 
} 

app.component.ts

constructor(){ 
this.sendGPSStart() 
this.interval() 
} 

sendGPSStart(){ 
    this.locationTracker.startTracking(); 
    } 

    sendGPSStop(){ 
    this.locationTracker.stopTracking(); 
} 

interval(){ 
setInterval(() => { 
     this.sendGPSStart() 
      this.sendGPSStop() 
    }, '30000') 

} 

Odpowiedz

1

Patrząc na przykłady np dnchia/Ionic3-Background-Geolocation można skonfigurować interwał na tle, a także okresowego planie wysłać

gps.ts

startTracking(interval) { 

    console.log('started tracking') 
    const config: BackgroundGeolocationConfig = { 
     desiredAccuracy: 10, 
     stationaryRadius: 20, 
     distanceFilter: 30, 
     debug: false, // enable this hear sounds for background-geolocation life-cycle. 
     stopOnTerminate: false, 
     interval: interval 
    }; 

app.component.ts

interval = 30000; 

constructor() { 
    this.sendGPSStart() 
    this.interval() 
} 

sendGPSStart(){ 
    this.locationTracker.startTracking(this.interval); 
} 

sendGPSStop(){ 
    this.locationTracker.stopTracking(); 
} 

interval() { 
    setInterval(() => { 
    this.locationTracker.sendGPS(); 
    }, this.interval) 

} 
+0

Niestety, to podejście działa tylko w systemie Android. – userlkjsflkdsvm