2017-07-21 9 views
0

私はこのサンプルコードをJosh Moronyさん( )に従おうとしていますが、これを修正する方法が見つからないようです。LocationTrackerのすべてのパラメータを解決できません

コンソールからエラーが表示され、Webrowser上に表示され、さらにはデバイス上に表示されます。

私はプラグインを追加しました:ここ

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

はエラーメッセージ

Uncaught Error: Can't resolve all parameters for LocationTracker: ([object Object], [object Object], [object Object], ?).at syntaxError (file:///android_asset/www/build/vendor.js:79310:34) 
    at CompileMetadataResolver._getDependenciesMetadata (file:///android_asset/www/build/vendor.js:92647:35) 
    at CompileMetadataResolver._getTypeMetadata (file:///android_asset/www/build/vendor.js:92515:26) 
    at CompileMetadataResolver._getInjectableMetadata (file:///android_asset/www/build/vendor.js:92501:21) 
    at CompileMetadataResolver.getProviderMetadata (file:///android_asset/www/build/vendor.js:92791:40) 
    at file:///android_asset/www/build/vendor.js:92720:49 
    at Array.forEach (native) 
    at CompileMetadataResolver._getProvidersMetadata (file:///android_asset/www/build/vendor.js:92681:19) 
    at CompileMetadataResolver.getNgModuleMetadata (file:///android_asset/www/build/vendor.js:92336:50) 
    at JitCompiler._loadModules (file:///android_asset/www/build/vendor.js:103400:66) 

ページ/ホーム/ home.ts

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular'; 
import { LocationTracker } from '../../providers/location-tracker/location-tracker'; 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 
export class HomePage { 

constructor(public navCtrl: NavController, public locationTracker: LocationTracker) { 

    this.startTracking(); 
    } 

    startTracking(){ 
    this.locationTracker.startTracking(); 
    } 

    stopTracking(){ 
    this.locationTracker.stopTracking(); 
    } 
} 

/ページ/ホーム/ホームです。 html

<ion-content padding> 
    <ion-label>Current Latitude: {{locationTracker.lat}</ion-label> 
    <ion-label>Current Longitude: {{locationTracker.lng}}</ion-label> 
</ion-content> 

/providers/location-tracker/location-tracker.ts

import { Injectable, NgZone } from '@angular/core'; 
import { BackgroundGeolocation } from '@ionic-native/background-geolocation'; 
import { Geolocation, Geoposition } from '@ionic-native/geolocation'; 
import 'rxjs/add/operator/map'; 
import 'rxjs/add/operator/filter'; 

@Injectable() 
export class LocationTracker { 

    public watch: any;  
    public lat: number = 0; 
    public lng: number = 0; 

    constructor(public zone: NgZone, public backgroundGeolocation: BackgroundGeolocation, public geolocation: Geolocation, public geoposition: Geoposition) { 

    } 

    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.lat = location.latitude; 
     this.lng = location.longitude; 
     }); 

    }, (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.lat = position.coords.latitude; 
     this.lng = position.coords.longitude; 
     }); 

    }); 
    } 

    stopTracking() { 
    console.log('stopTracking'); 

    this.backgroundGeolocation.finish(); 
    this.watch.unsubscribe(); 
    } 
} 

アプリ/

import { BrowserModule } from '@angular/platform-browser'; 
import { ErrorHandler, NgModule } from '@angular/core'; 
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; 
import { MyApp } from './app.component'; 
import { HomePage } from '../pages/home/home'; 
import { StatusBar } from '@ionic-native/status-bar'; 
import { LocationTracker } from '../providers/location-tracker/location-tracker'; 
import { BackgroundGeolocation } from '@ionic-native/background-geolocation'; 
import { Geolocation } from '@ionic-native/geolocation'; 


@NgModule({ 
    declarations: [ 
    MyApp, 
    HomePage 
    ], 
    imports: [ 
    BrowserModule, 
    IonicModule.forRoot(MyApp), 
    HttpModule 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
    MyApp, 
    HomePage 
    ], 
    providers: [ 
    StatusBar 
    {provide: ErrorHandler, useClass: IonicErrorHandler} 
    LocationTracker, 
    BackgroundGeolocation, 
    Geolocation 
    ] 
}) 
export class AppModule {} 
+0

をそれはイオン2または3にすることができますが、両方にすることはできません。 ) – onetwo12

+0

こんにちはonetwo12、 あなたはタギングを参照していますか? –

+0

私はあなたが何を意味するかを見ます。私はこのエラーが両方にあると想定しています。 –

答えて

2

エラーを見てtaje場合、それは第四と言うのapp.module.tsパラメータは、注射

からあなたのコードを見てみると
Uncaught Error: Can't resolve all parameters for LocationTracker: ([object Object], [object Object], [object Object], ?) 

を注入することができませんでした
constructor(public zone: NgZone, 
      public backgroundGeolocation: BackgroundGeolocation, 
      public geolocation: Geolocation, 
      public geoposition: Geoposition) { 
} 

4番目のGeopositionは、あなたがNgModuleに「提供していない」ようです。

だから、限り、あなたはこの「地理位置」インスタンス/オブジェクトを使用していないとして、あなたは単にコンストラクタからそれを削除することができます。

constructor(public zone: NgZone, 
      public backgroundGeolocation: BackgroundGeolocation, 
      public geolocation: Geolocation) { 
} 
+0

いいえ..あなたの説明は、私がエラーを少し良く読む方法を理解するのを助けました... – JGFMK

+0

多くの感謝!私は今それを見る。私は明日までにそれをテストしたら、これを答えにします。 –

+0

あなたはそれをとてもよく正確に説明しました。 –

関連する問題