在ionic3中打开背景模式后,地图标记被删除了吗?

时间:2019-05-20 06:22:45

标签: google-maps-api-3 geolocation ionic3 background-mode

我创建了一个跟踪应用程序,其中在我们的应用程序中打开后台模式后删除了谷歌地图标记,我调试了它,但在控制台中未在控制台中显示任何错误。我正在使用后台模式插件获取纬度和时间用户锁定我们的手机后的值。请检查下面的代码,我的代码有什么问题?

//ON backgrund mode here...
 platform.ready().then(() => {
    this.backgroundMode.on('activate').subscribe(() => {
       //trigger function only if location updated.....
      this.platform.ready().then(() => this.getUserPosition());
    });
    this.backgroundMode.enable();
  })
  
  //getUserPosition for get position....  
  getUserPosition(){
    let mapOptions = {
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: false,
      streetViewControl: false,
      fullscreenControl: false,
      draggable : true
    } 

    if(this.mapElement) {
      this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
    } 

    if(this.currentUserObject) {
       //get user currentLocation and update user location after move move    
       this.geolocation.watchPosition().subscribe((position) => {
        var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

          console.log('lat fire1.....', +position.coords.latitude);
          console.log('long fire.....', +position.coords.longitude);

          this.map.setCenter(latLng);
          this.map.setZoom(16);
         //set the market initially...
        this.moveMarker(position);
       }, (err) => {
           console.log(err);
       });
    }
   }
   
   
   //marker update 
     moveMarker(position: any){ 

     //Create a new viewpoint bound    
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    var coords = new google.maps.LatLng(latitude, longitude);

    if(this.cont<1){
      this.marker = new google.maps.Marker({
        position: coords,
        strokeColor: '#40710C',
        map: this.map,
        title: 'HI!! HI´M HERE!',
        icon: { url : './assets/imgs/user_location.gif'}
      });
      this.cont=this.cont + 1;

      //Create a new viewpoint bound
      var bounds = new google.maps.LatLngBounds();
      bounds.extend(coords);
      //  Fit these bounds to the map
      this.map.fitBounds(bounds);//set zoom
      this.map.panToBounds(bounds); 

       //updateDriverLocation for get driver updated location...
      this.updateDriverLocation(latitude, longitude);
      this.speed = position.coords.speed * 3.6;

    } else {

      this.marker.setPosition(coords);
      this.map.panTo(coords); 

      //updateDriverLocation for get driver updated location...
      this.updateDriverLocation(latitude, longitude);
      this.speed = position.coords.speed * 3.6;
    }
   }

0 个答案:

没有答案