Giter Site home page Giter Site logo

For identical travel path total calculated distance is different from the location updates in server . about cordova-background-geolocation-lt HOT 18 CLOSED

RintuMondal06 avatar RintuMondal06 commented on May 25, 2024
For identical travel path total calculated distance is different from the location updates in server .

from cordova-background-geolocation-lt.

Comments (18)

christocracy avatar christocracy commented on May 25, 2024 1

Called then state.enabled is by default true right?

No. The plugin is disabled by default. Calling .ready(config) does NOT imply "start tracking". Only calling .start() initiates tracking.

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

If your driver is stopped, you should tell the plugin to .stop().

Setting the url to '' is not going to stop the plugin continuing to record locations and insert them into its database.

See api docs Config.maxRecordsToPersist.

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

Also read the api docs "HTTP Guide", linked througout.

from cordova-background-geolocation-lt.

RintuMondal06 avatar RintuMondal06 commented on May 25, 2024

If your driver is stopped, you should tell the plugin to .stop().

Setting the url to '' is not going to stop the plugin continuing to record locations and insert them into its database.

See api docs Config.maxRecordsToPersist.

@christocracy Thank you very much for your reply!! are you suggesting making the plugin start/stop with respect to ride start and end? If yes how can I prevent the plugin from recording the locations? Because with .ready() the plugin starts recording the locations.

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

Calling .ready(config) restores the plugin to its last known state according to State.enabled.

  • .start() -> State.enabled == true
  • .stop() -> State.enabled == false

The plugin stores State.enabled in permanent storage. It is "remembered" even after app terminate / device reboot.

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

If you call .stop(), terminate then restart your app, you will find that State.enabled == false and the plugin will NOT call .start() upon itself after .ready(config) is called.

BackgroundGeolocation.ready(config).then((state) => {
  console.log('State.enabled? ', state.enabled);
});

from cordova-background-geolocation-lt.

RintuMondal06 avatar RintuMondal06 commented on May 25, 2024

For the first time when the app is loaded with .ready() called then state.enabled is by default true right? But in my case i want to track location only when a ride is on-going. So should I call .stop() at the first time by myself?

from cordova-background-geolocation-lt.

RintuMondal06 avatar RintuMondal06 commented on May 25, 2024

Thanks for your help @christocracy !! I am stuck here for a long time. I'll change my code and check.

from cordova-background-geolocation-lt.

gfernandez87 avatar gfernandez87 commented on May 25, 2024

Dear good afternoon, I wanted to ask you if it is mandatory to configure an api (url). I have to make an application that retrieves the coordinates and inserts them into a SQLite database, but the application will not have an internet connection so I cannot configure an API, is it possible for it to work locally? Thank you so much

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

No, it's not mandatory. Simply DO NOT even provide an url.

Be aware that the plug-in inserts each recorded location into its own SQLite db and collects 3 days worth by default. You will may want to configure Config.persistMode accordingly (PERSIST_MODE_NONE).

If you wish to take advantage of the plug-in's SQLite db, see .getLocations and .destroyLocations.

from cordova-background-geolocation-lt.

gfernandez87 avatar gfernandez87 commented on May 25, 2024

Dear, thank you very much for your response. I'll bother you with two more queries if possible. I am setting locationUpdateInterval to 1 second, because I need to show the time in which the vehicle is stopped, the problem I have is that initially the tracking is not executed every one second, until it detects a movement, is this normal? . And the other problem I have is that for example when I am in the "walking" state and I brake there is a delay in changing to the "still" state of approximately 15 seconds, the same when I change from "still" to "walking". I am setting it up as follows:

configureBackgroundGeolocationDos() {
    // 1.  Listen to events.
    BackgroundGeolocation.onLocation(location => {
      // Calcular la distancia entre la ubicación actual y la anterior
      console.log('[location] - ', location);
      this.listaPuntosViaje.push(location.coords)
      if (!this.ubicacionAnterior || this.ubicacionAnterior == null) {
        this.ubicacionAnterior = location.coords;
        return;
      }

      this.mostrarMensaje("ACTIVIDAD " + location.activity.type)
      if (location.activity.type == 'running') { //CORRIENDO

      }
      if (location.activity.type == 'still') { //CORRIENDO
        this.tiempoDeParadaSegundos += 1;
      }
      if (location.activity.type == 'on_foot') { // A PIE

      }

      if (location.activity.type == 'on_bicycle') { // EN BICICLETA

      }
      if (location.activity.type == 'in_vehicle') { // EN VEHICULO

      }

      if (location.activity.type == 'unknown') { // DESCONOCIDO

      }

      let velocidad = location.coords.speed == undefined ? 0 : location.coords.speed;
      if (velocidad > 0) {
       this.velocidad = velocidad * 3.6; // Convertir de m/s a km/h
      }
      else {
        this.velocidad = 0;
      }


      if (location.activity.type == 'walking' || location.activity.type == 'in_vehicle') {
       
        this.mostrarMensaje(location.activity.type)

        const distancia = this.pruebaDistancia(this.ubicacionAnterior.latitude, this.ubicacionAnterior.longitude,
          location.coords.latitude, location.coords.longitude)
        this.distanciaRecorrida += distancia;
        
      }
      this.cdr.detectChanges();

      this.ubicacionAnterior = location.coords;

    });

    BackgroundGeolocation.onMotionChange(event => {
      console.log('[motionchange] - ', event.isMoving, event.location);
    });

    BackgroundGeolocation.onHttp(response => {
      console.log('[http] - ', response.success, response.status, response.responseText);
    });

    BackgroundGeolocation.onProviderChange(event => {
      console.log('[providerchange] - ', event.enabled, event.status, event.gps);
    });

    // 2.  Configure the plugin with #ready
    BackgroundGeolocation.ready({
      
      reset: true,
      debug: true,
      logLevel: BackgroundGeolocation.LOG_LEVEL_OFF,
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 0,
      disableElasticity: true,
      locationAuthorizationRequest: "Any",
      locationUpdateInterval: 2000,
      fastestLocationUpdateInterval: 2000,
      maxDaysToPersist: 0, maxRecordsToPersist: 0, //VER ESTO DESHABILITA GUARDAR EN SQLLITE 
      stopOnStationary: false,
      // url: 'http://my.server.com/locations',
      allowIdenticalLocations: false,
      autoSync: true,
      stopOnTerminate: true,
      startOnBoot: false, persistMode: BackgroundGeolocation.PERSIST_MODE_NONE,
      notification: {
        title: 'TEST', 
        text: 'TEXT', 
        color: '#FFFFFF', 
        channelName: 'Geolocation', 
        priority: -1
    },
    }, (state) => {
      console.log('[ready] BackgroundGeolocation is ready to use');
      if (!state.enabled) {
        // 3.  Start tracking.
        BackgroundGeolocation.start();
      }
    });
  }

I hope you can help me and thank you very much in advance!!

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

Please learn to syntax highlight fenced codeblocks

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

the problem I have is that initially the tracking is not executed every one second, until it detects a movement, is this normal?

The native location api returns locations when it feels like it. The plug-in merely "turns it on".

when I am in the "walking" state and I brake there is a delay in changing to the "still" state of approximately 15 seconds

The same go for the native location api. The plug-in turns it ON -- it's totally up to the OS to return results when it feels like it. There's nothing you can do to "fine tune" it or make it returns results faster.

from cordova-background-geolocation-lt.

gfernandez87 avatar gfernandez87 commented on May 25, 2024

Thank you again for your prompt response! One last question, I understand that it is not, but just in case I ask it, there is no functionality that returns the kilometers or meters traveled since BackgroundGeolocation.start() was started; until BackgroundGeolocation.stop()? is finished. This should be calculated by taking the distance between the last coordinate and the new coordinate and accumulating it in a variable, right?

Sorry for the inconvenience and thank you again!

from cordova-background-geolocation-lt.

christocracy avatar christocracy commented on May 25, 2024

Search the api docs "odometer"

from cordova-background-geolocation-lt.

gfernandez87 avatar gfernandez87 commented on May 25, 2024

Search the api docs "odometer"

Thank you so much!!

from cordova-background-geolocation-lt.

github-actions avatar github-actions commented on May 25, 2024

This issue is stale because it has been open for 30 days with no activity.

from cordova-background-geolocation-lt.

github-actions avatar github-actions commented on May 25, 2024

This issue was closed because it has been inactive for 14 days since being marked as stale.

from cordova-background-geolocation-lt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.