离子背景地理位置恢复正常,但我无法获取位置

时间:2019-05-31 15:46:13

标签: ionic-framework

我正在制作具有跟踪功能的应用程序,无论如何,我正在使用this plugin。当我尝试获取位置时,输出正常。

据我了解,location.longitude应该显示经度,但不能显示,经度是BackgroundGeolocationResponse,但不是显示“确定”。

const config: BackgroundGeolocationConfig = {
  desiredAccuracy: 50,
  stationaryRadius: 1,
  distanceFilter: 1,
  debug: true, //  enable this hear sounds for background-geolocation life-cycle.
  stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};

this.backgroundGeolocation.configure(config)
  .then((location: BackgroundGeolocationResponse) => {
    console.log("Here you should see the location");
    console.log(location);
    console.log(location.longitude);
    console.log("Here you should see the End location");

  });

// start recording location
this.backgroundGeolocation.start();

所以问题是,当我尝试在android设备上运行它时,得到了此输出

[INFO:CONSOLE(762)] "Here you should see the location"
[INFO:CONSOLE(763)] "OK"
[INFO:CONSOLE(764)] "undefined"
[INFO:CONSOLE(765)] "Here you should see the End location"

如何获取位置?!

1 个答案:

答案 0 :(得分:0)

使用订阅代替然后

this.backgroundGeolocation.configure(config)
   .subscribe((location: BackgroundGeolocationResponse) => {
   console.log("Here you should see the location")

    console.log(location.longitude)


 });