Маркер карты удаляются после включения фонового режима в ionic3? - PullRequest
0 голосов
/ 20 мая 2019

У меня есть приложение для отслеживания, в котором маркер карты google удаляется после включения фонового режима в нашем приложении. Я отладил его, но в консоли не выдает никаких ошибок в консоли. Я использую плагин фонового режима для получения широты и долготы.Значение после того, как пользователь заблокирует наш телефон. Пожалуйста, проверьте код ниже, и что не так в моем коде?

//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;
    }
   }
...