Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49526

How to print the results of Background Geolocation?

$
0
0

@ioclaudio wrote:

Hi,
I’m using the plugin for the background geolocation (@mauron85/cordova-plugin-background-geolocation": “^3.0.7”) to get the speed and the position of a device in an Ionic4 app.

It seems that the plugin returns the right data, but I can’t show them in an Ionic page.

This is the page that should show the data:

    <ion-row>
      <ion-col>
        <span>{{'Speed raw'}}</span>
      </ion-col>
      <ion-col>
        <span>{{ geolocationSpeedRaw  }}</span>
      </ion-col>
    </ion-row>
    <ion-row>
      <ion-col>
        <span>{{'Speed'}}</span>
      </ion-col>
      <ion-col>
        <span>{{ geolocationSpeed | number:'1.1-2' }}</span>
      </ion-col>
    </ion-row>
    <ion-row>
      <ion-col>
        <span>{{'Latitude'}}</span>
      </ion-col>
      <ion-col>
        <span>{{ geolocationLat }}</span>
      </ion-col>
    </ion-row>
    <ion-row>
      <ion-col>
        <span>{{'Longitude'}}</span>
      </ion-col>
      <ion-col>
        <span>{{ geolocationLong }}</span>
      </ion-col>
    </ion-row>

This is the code that should update the page:

  startGeolocation() {

    this.showSpinner = true;
    this.geolocationSpeedRaw = '-';
    this.geolocationSpeed = 0;
    this.geolocationLat = 0;
    this.geolocationLong = 0;


    // start recording location
    this.backgroundGeolocation.configure(BACKGROUND_GEOLOCATION_CONFIG).then(() => {
      this.backgroundGeolocation
        .on(BackgroundGeolocationEvents.location)
        .subscribe((location: BackgroundGeolocationResponse) => {

          alert('Speed: ' + location.speed);

          try {
            this.geolocationSpeedRaw = String(location.speed);
          } catch (e) {
            alert('Error geolocationSpeedRaw');
          }

          try {
            this.geolocationSpeed = Number.isNaN(location.speed) ? 0 : (location.speed * 3.6);
          } catch (e) {
            alert('Error geolocationSpeed');
          }

          try {
            this.geolocationLat  = location.latitude;
          } catch (e) {
            alert('Error geolocationLat');
          }

          try {
            this.geolocationLong  = location.longitude;
          } catch (e) {
            alert('Error geolocationLong');
          }


          this.backgroundGeolocation.finish();
        });
    });
}

The problem is that the alert shows the right speed, but the content of the page is never updated.
No other alerts are shown, so I don’t think that the assignments generate an error.
So, why the page never updates?

it seems that Ionic does not notice that the value of the variable has changed.
Is it possible?

Thank you

Claudio

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49526

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>