Hello everyone,
I am trying to make a routes creator with ionic, but i get stock with this. I am using ionic 5 with capacitor on android 10.
This is my code:
import { Component } from '@angular/core';
import {
BackgroundGeolocation,
BackgroundGeolocationConfig,
BackgroundGeolocationEvents,
BackgroundGeolocationResponse,
BackgroundGeolocationLocationProvider
} from '@ionic-native/background-geolocation/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
location: BackgroundGeolocationResponse;
config: BackgroundGeolocationConfig = {
locationProvider: BackgroundGeolocationLocationProvider.DISTANCE_FILTER_PROVIDER,
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 0.1,
interval: 1000,
debug: false, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: true, // enable this to clear background location settings when the app terminates
};
constructor(private backgroundGeolocation: BackgroundGeolocation) {
this.backgroundGeolocation.configure(this.config)
.then(() => {
this.backgroundGeolocation.on(BackgroundGeolocationEvents.location)
.subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
this.location = location;
})
}).catch((error) => {
console.error(error);
});
this.backgroundGeolocation.start();
}
startBackgroundLocation(){
this.backgroundGeolocation.start();
}
ngOnDestroy() {
this.backgroundGeolocation.stop();
}
}
The thing is actually workin or its looks like because y the android studio terminal i am getting this :
D/com.tenforwardconsulting.bgloc.DistanceFilterLocationProvider: Location change: Location[gps 37,267922,-4,412952 hAcc=20 et=+12d18h59m5s236ms alt=498.593017578125 vel=0.0 vAcc=24 sAcc=1 bAcc=??? {Bundle[mParcelledData.dataSize=96]}] isMoving=true
D/com.marianhello.bgloc.service.LocationServiceImpl: New location BGLocation[gps 37,267922,-4,412952 id=null acc=20 t=1602590769000 et=+12d18h59m5s236ms alt=498.593017578125 vel=0.0 {Bundle[mParcelledData.dataSize=96]} locprov=0]
D/com.marianhello.bgloc.BackgroundGeolocationFacade: Received MSG_ON_LOCATION
Until I get this error:
E/Perf: Fail to get file list io.ionic.starter
E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
Fail to get file list io.ionic.starter
getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
The this is the suscription it’s not working so I cant get the data, and I really want to get a background geolocation to make routes. There is another way to do this?. I am making a mistake?.
Regards.