首页 > 解决方案 > BackgroundGeolocation 不在后台工作,但在前台火灾中为什么?

问题描述

团队我已经在我们的应用程序中实现了跟踪功能并使用了 BackgroundGeolocation,但它在我们提到的场景下面无法在后台工作:

情况1:

如果我是前台而不是后台,则 BackgroundGeolocation 仅触发 1 次,下面我们用于 BackgroundGeolocation 的链接:

https://www.joshmorony.com/adding-background-geolocation-to-an-ionic-2-application/

https://www.freakyjolly.com/ionic-3-get-background-device-location-using-cordova-and-ionic-native-geolocation-plugins/

我已经尝试了上面的链接,但我得到了相同的结果。我真的在 ionic3 中遇到了位置问题,而且任何查询都不支持 ionic 社区。

   loadLocation(){
   // foreground Tracking
   var self = this;
          //get user currentLocation and update user location after move move    
      self.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {

        //self.subscription = self.watch.subscribe((position) => {
        var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

        console.log('lat fire1.....', +position.coords.latitude);
        console.log('long fire.....', +position.coords.longitude);

        //set center to map and set zoom....
        self.map.setCenter(latLng);
        self.map.setZoom(16);

        //updateDriverLocation for get driver updated location...
        self.updateDriverLocation(position.coords.latitude, position.coords.longitude);

        //moveMarker for ,move marker......
        self.moveMarker(position);
      }, (err) => {
          console.log(err);
      });

      // Background Tracking
      let config = {
        desiredAccuracy: 0,
        stationaryRadius: 20,
        distanceFilter: 10, 
        debug: true,
        interval: 2000 
      };

      this.backgroundGeolocation.configure(config).subscribe((location) => {
        alert('dddddd');
        console.log('BackgroundGeolocation:  ' + location.latitude + ',' + location.longitude);
            //updateDriverLocation for get driver updated location...
          self.updateDriverLocation(location.latitude,location.longitude);
          self.moveMarker(location);
      }, (err) => {
        console.log(err);
      });
      // Turn ON the background-geolocation system.
      this.backgroundGeolocation.start();
   }

我尝试了所有方法,但没有任何效果,请团队帮助我。

标签: geolocationionic3

解决方案


推荐阅读