SetIntervel to update Background Mode not working


#1

In constructor, I’m doing platform.ready to run Background. It show value of latitude and longitude but won’t update it. Don’t know why.

that.platform.ready().then(() => {
      this.task = setInterval(() => {
        navigator.geolocation.getCurrentPosition(function (position) {
          that.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + position.coords.latitude + ',' + position.coords.longitude + '&key=AIzaSyCnFxcopJ1KvuCfnz2mHgUiZmmKd3eidEE').map(res => res.json()).subscribe(data => {
            that.myPos = data.results[0].address_components[1]['long_name'];
          });

          cordova.plugins.backgroundMode.setDefaults({
            title: 'My App Name',
            text: 'Lat: ' + position.coords.latitude + '  Long' + position.coords.longitude + ''
          });
        });

        cordova.plugins.backgroundMode.enable();
      }, 7000);
    });