2017-06-07 48 views
1

我目前面臨的問題不是很好。我已經創建了一個問題,但沒有迴應。我需要每個位置更改以更新相機中心位置。但是這並沒有發生。刷新不能隨着時間的推移而定義。這對我的需求來說非常罕見。 Android和iOS是一樣的。日誌被稱爲每分鐘或類似的東西。 另外我試過在ngZone之外的控制檯日誌,但它是一樣的。 這是我的配置代碼如下所示:Ionic 3:BackgroundLocation更新太少了

let config = { 
    desiredAccuracy: 0, 
    stationaryRadius: 1, 
    distanceFilter: 0, 
    debug: true, 
    interval: 2000, 
    pauseLocationUpdates: false, 
    activityType: "AutomotiveNavigation" 
}; 

this.backgroundGeolocation.configure(config).subscribe((location) => { 
    // Run update inside of Angular's zone 
    this.zone.run(() => { 
    if(this.map) { 
     this.map.getMyLocation().then((userLocation: MyLocation) => { 
     console.log("INSIDE ZONE Google Maps Location \n LAT: " + userLocation.latLng.lat + "\nLNG: " + userLocation.latLng.lng); 
     this.userLocation = userLocation.latLng; 
     this.speed = userLocation.speed; 
     this.bearing = userLocation.bearing; 
     this.altitude = location.altitude; 

     this.cameraFollow(); 
     this.notify(this.nearestReports[0]); 
     }).catch(error => { 
     alert("Background - NO GPS FOUND: " + error); 
     }); 
    } 
    }); 
}); 

// Turn ON the background-geolocation system. 
this.backgroundGeolocation.start(); 

回答

0

考慮使用所謂的Geolocation另一種離子本地插件。

在那裏有一個非常方便的watchPosition()函數,看起來像你在找什麼。這裏有一個例子:

let options = { 
    enableHighAccuracy: true, 
    timeout: Infinity, // don't return response until new ping is available from OS, to save battery 
    maximumAge: 0 
}; 

const subscription = this.geolocation.watchPosition(options) 
    .filter((p) => p.coords !== undefined) //Filter Out Errors 
    .subscribe(position => { 
     console.log(position.coords.longitude + ' ' + position.coords.latitude); 
}); 

不要忘記停止訂閱時,爲了節省電池不需要:

subscription.unsubscribe(); 
+0

但這個插件是不工作的背景位置是不是? – TdoubleG

+0

老實說,我不確定。我檢查了[Android如何處理後臺位置服務](https://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app .PendingIntent))雖然(你使用的插件取決於),它說'位置更新之間的時間間隔永遠不會小於minTime,儘管它可能更多取決於位置提供程序實現和其他應用程序請求的更新間隔'。所以在後臺真的沒有辦法將它最小化。 – maninak

+0

我希望這已經回答了你的問題。 – maninak