【问题标题】:Background geolocation not work in ionic 3 in background后台地理定位在后台的 ionic 3 中不起作用
【发布时间】:2020-04-22 06:46:05
【问题描述】:

当应用程序在 Ionic 3 中处于后台时,Cordova 插件 background-geolocation 不起作用。此代码在 app.component.ts 文件中调用。此代码仅在前台调用该 web 服务,而不是在后台或屏幕关闭。

 startTracking() {
    // Background Tracking
    let config = {
      desiredAccuracy: 0,
      stationaryRadius: 20,
      distanceFilter: 10, 
      debug: true,
      interval: 2000 
    };
    this.backgroundGeolocation.configure(config).subscribe((location) => {
      console.log('BackgroundGeolocation:  ' + location.latitude + ',' + location.longitude);
      // Run update inside of Angular's zone
      this.zone.run(() => {
        this.geoLatitude = location.latitude;
        this.geoLongitude = location.longitude;
        this.TrackLiveLocation();//for call our private webservice
    });
      });
    }, (err) => {
      console.log(err);
    });
    // Turn ON the background-geolocation system.
    this.backgroundGeolocation.start();
    // Foreground Tracking
  let options = {
    frequency: 3000, 
    enableHighAccuracy: true
  };
  this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {
    console.log(position);
    // Run update inside of Angular's zone
    this.zone.run(() => {
      this.geoLatitude = position.coords.latitude;
      this.geoLongitude = position.coords.longitude;
      this.TrackLiveLocation();//for call our private webservice
    });
  });
  }

【问题讨论】:

    标签: android background geolocation ionic3 tracking


    【解决方案1】:

    原生与混合 Android 8 及更高版本的最新更新的一个副作用是位置 API 将需要原生应用程序开发。 因为通过 React Native、Flutter、Cordova、Ionic 或 Xamarin 等混合框架的直接控制将不再有效。 混合应用开发者需要为位置访问构建原生功能。

    根据最新的 Android 政策和后台服务更新,离子插件在前台工作,但不在后台工作。

    policy for background mode

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 2017-09-23
      • 1970-01-01
      • 2019-07-02
      • 2013-09-27
      相关资源
      最近更新 更多