2017-04-01 2 views
0

배경 지오 로케이션을 사용 하려는데이 링크를 발견했습니다. [a 링크] https://www.joshmorony.com/adding-background-geolocation-t ... /. "Geoposition is knwon"유형 스크립트 오류가 아닙니다.배경 Geolocation Ionic2의 경우

이온 버전 : 2.2.1, 노드 버전 : 6.10.0, 코르도바 버전 : 가정하면 ionic2 geoloca

location-tracker : 
 

 

 
import { Injectable, NgZone } from '@angular/core'; 
 
import { Geolocation,Geoposition, BackgroundGeolocation } from 'ionic-native'; 
 
import 'rxjs/add/operator/filter'; 
 
    
 
@Injectable() 
 
export class LocationTracker { 
 
    
 
    public watch: any;  
 
    public lat: number = 0; 
 
    public lng: number = 0; 
 
    
 
    constructor(public zone: NgZone) { 
 
    
 
    } 
 
    
 
    startTracking() { 
 
// Background Tracking 
 
    
 
    let config = { 
 
    desiredAccuracy: 0, 
 
    stationaryRadius: 20, 
 
    distanceFilter: 10, 
 
    debug: true, 
 
    interval: 2000 
 
    }; 
 
    
 
    BackgroundGeolocation.configure((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); 
 
    
 
    }, config); 
 
    
 
    // Turn ON the background-geolocation system. 
 
    BackgroundGeolocation.start(); 
 
    
 
    
 
    // Foreground Tracking 
 
    
 
    let options = { 
 
    frequency: 3000, 
 
    enableHighAccuracy: true 
 
    }; 
 
    
 
    this.watch = 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'); 
 
    
 
    BackgroundGeolocation.finish(); 
 
    this.watch.unsubscribe(); 
 
    
 
    } 
 
    
 
}

+0

우리에게 실제 코드를 보여주세요 .. – yaboiduke

답변

0

에 대한 6.5.0 .ANY 제안 이미 다음 명령을 실행했습니다. 다음과 같이 플러그인을 가져

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

시도 :

import { BackgroundGeolocation } from '@ionic-native/background-geolocation'; 
import { Geolocation, Geoposition } from '@ionic-native/geolocation';