简体   繁体   English

后台地理定位在后台的 ionic 3 中不起作用

[英]Background geolocation not work in ionic 3 in background

Cordova plugin background-geolocation does not work when the app is in the background in Ionic 3. This code called in the app.component.ts file.当应用程序在 Ionic 3 中处于后台时,Cordova 插件 background-geolocation 不起作用。此代码在 app.component.ts 文件中调用。 This code calls that webservice on foreground only not in background or in screen off.此代码仅在前台调用该 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
    });
  });
  }

Native v/s Hybrid A side impact of the latest updates of Android 8 onwards is that location APIs will require native app development. Native v/s Hybrid Android 8 及以后的最新更新的一个副作用是位置 API 将需要本地应用程序开发。 because Direct control through hybrid frameworks like React Native, Flutter, Cordova, Ionic, or Xamarin will no longer work.因为通过 React Native、Flutter、Cordova、Ionic 或 Xamarin 等混合框架进行直接控制将不再有效。 Hybrid app developers will need to build native functionality for location access.混合应用程序开发人员将需要为位置访问构建本机功能。

ionic plugin is working for foreground but not working in background as per latest Android policy and update for background service.根据最新的 Android 政策和后台服务更新,离子插件在前台工作,但不在后台工作。

policy for background mode 后台模式策略

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM