2017-06-07 47 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