我目前正在面临一个不太好的问题。我已经创建了一个问题,但没有回应。我需要每个位置更改以更新相机中心位置。但这不会发生。刷新无法随时间定义。对于我的需求来说,这是非常罕见的。Android和iOS是一样的。该日志每分钟或类似的东西称为。我还尝试了ngZone
外的控制台日志,但相同。这就是我的配置代码的样子:
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();
考虑使用另一个称为 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();