我是Ionic和Typescript的新手,如果我对这张脸有屁股,那么道歉!
我试图用Ionic 2构建一个简单的iOS和Android应用程序,只显示用户当前位置,在移动时进行更新.
我面临的问题是,虽然我似乎正在通过UI获取坐标位置,但永远不会更新以显示更新的位置.
我使用cordova-plugin-mauron85-background-geolocation插件创建了一个提供程序作为location.ts:
import { Injectable, NgZone} from '@angular/core';
import { BackgroundGeolocation } from 'ionic-native';
@Injectable()
export class LocationProvider {
public message: any = "I'm new here";
public latitude:number = 0.0;
public longitude:number = 0.0;
private zone: NgZone;
constructor() {
this.initialiseLocationManager();
}
initialiseLocationManager() {
let config = {
desiredAccuracy: 1,
stationaryRadius: 1,
distanceFilter: 1,
interval:1000,
activityType:'AutomotiveNavigation',
debug: true,
stopOnTerminate: true,
};
BackgroundGeolocation.configure(config)
.then(this.locationUpdated)
.catch((error) => {
console.log('BackgroundGeolocation error');
});
}
private locationUpdated(location) {
console.log('******* NEW LOCATION ********');
this.zone.run(() …Run Code Online (Sandbox Code Playgroud)