【问题标题】:Background Geolocation isn't a Observable背景地理位置不是可观察的
【发布时间】:2019-01-31 01:12:40
【问题描述】:

我需要在我的应用中实现后台地理位置。我访问了这个ionic documentation,代码如下:

this.backgroundGeolocation.configure(config)
  .subscribe((location: BackgroundGeolocationResponse) => {

    console.log(location);

    // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
    // and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
    // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
    this.backgroundGeolocation.finish(); // FOR IOS ONLY

  });

当我在我的应用程序中使用此代码时,我的 ts-lint 指责 configure(config) 方法是 Promise<any> 而不是 Observable,所以,我不能使用 subscribe。我将subscribe 切换为then。但是当我运行时,会在下面显示此错误:

ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at BackgroundGeolocation.configure (vendor.js:82333)
// error below ommited

有人可以帮助我吗?

【问题讨论】:

    标签: cordova ionic-framework geolocation ionic3


    【解决方案1】:

    问题在于插件版本。在 Ionic 3 中,这个版本可以正常工作:

    config.xml 文件: <plugin name="cordova-plugin-mauron85-background-geolocation" spec="^2.2.5" />

    package.json 文件: "@ionic-native/background-geolocation": "^3.14.0",

    我在repository 中找到了这个答案。

    Ionic v3 documentation是错误的,因为那里说我们需要使用这个命令:

    $ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@alpha
    $ npm install --save @ionic-native/background-geolocation@4
    

    但我们需要使用此命令才能正常工作,最后使用subscribe

    $ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@2.2.5
    $ npm install --save @ionic-native/background-geolocation@3
    

    【讨论】:

    • 我已经在上面安装了,但是遇到另一个错误任务':processDebugResources'的执行失败。?
    • 你可以试试这两种解决方案:firstsecond
    • 先生,第二个解决方案对我有用,但是先生,如果在更改用户位置后锁定那个时间“纬度和经度”没有得到电话,先生告诉我有什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2019-07-16
    • 2016-12-23
    • 2019-07-08
    • 2014-12-29
    • 1970-01-01
    相关资源
    最近更新 更多