Javascript 表位3

Javascript 表位3,javascript,ionic3,angular6,Javascript,Ionic3,Angular6,嗨,伙计们,我需要关于如何用爱奥尼亚3观看谷歌地图位置的帮助,我想在firebase中实时上传位置 在my home.ts中,我有以下代码: getMyPosition() { this.geolocation.getCurrentPosition().then((result) => { this.positionTruck = new google.maps.LatLng(result.coords.latitude, result.coords.longi

嗨,伙计们,我需要关于如何用爱奥尼亚3观看谷歌地图位置的帮助,我想在firebase中实时上传位置 在my home.ts中,我有以下代码:

    getMyPosition() {
    this.geolocation.getCurrentPosition().then((result) => {
      this.positionTruck = new google.maps.LatLng(result.coords.latitude, result.coords.longitude);
      const mapOptions = {
        zoom: 18,
        center: this.positionTruck,
        disableDefaultUI: true
      }    
      this.map = new google.maps.Map(document.getElementById('map'), mapOptions);
      this.truckMarker(this.positionTruck);

      let watch = this.geolocation.watchPosition();
      watch.subscribe((data) => {
      let truck = { latitude: data.coords.latitude, longitude: data.coords.longitude };
        this.truckService.updateGeolocation(this.truck.key, truck);
        console.log(data.coords)
      });

    }).catch((error) => {
      console.log('Erro ao tentar pegar sua localização ', error);
    })
  }
现在我有了更新truck.service的代码:

    update(key: string, truck: any) {
    return new Promise((resolve, reject) => {
      this.db.list(this.PATH)
            .update(key, (truck))
            .then(() => resolve())
            .catch((e) => reject())
    })
  }
这样,当我在设备上测试时,主页会在页面中刷新,为什么?
此表单是否正确地处于更新位置?请帮助。

导入:
从'@ionic native/Geolocation'导入{Geolocation,Geolocation}

并宣布:

public lat: number = 0;
public lng: number = 0; 
并添加您的代码

let options = {
      frequency: 3000,
      enableHighAccuracy: true
    };

this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {

  console.log(position.coords.latitude + '   ++++++++++ ' + position.coords.longitude);

  // Run update inside of Angular's zone
  this.zone.run(() => {
    this.lat = position.coords.latitude;
    this.lng = position.coords.longitude;
    );

  });

});

对,但我有一些问题,1-我在ionViewDidLoad()中调用getMyPosition()方法{this.getMyPosition();}getMyPosition(){this.geolocation.getCurrentPosition()。然后((结果)=>{…让watch=this.geolocation.watchPosition();watch.subscribe((数据)=>{我应该在这里放置watchposition吗?2-需要像我那样在服务中调用update方法let watch=this.geolocation.watchposition();watch.subscribe((数据)=>{let truck={latitude:data.coords.lation,longitude:data.coords.longitude};this.truckService.updategeLocation(this.truck.key,truck);如上所述?我在方法getMyPosition中调用此方法wacth ionviewDidLoad,构造函数?