react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

onLocation function called twice when location changes.

Open jnranawedo opened this issue 8 years ago • 3 comments

Here the ' onLocation ' function executes twice when location change is detected. On location change we are sending Local Notification to user. Due to this issue the notification fires twice.

Here is my configuration :

BackgroundGeolocation.on('location', this.onLocation, this.onError);
  BackgroundGeolocation.configure({
    desiredAccuracy: 0,
    distanceFilter: 1000, 
    stopTimeout: 0,
    debug: false, // <-- enable this hear sounds for background-geolocation life-cycle.
    logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false,   // <-- Allow the background-service to continue tracking when user     closes the app.
    startOnBoot: true,        // <-- Auto start tracking when device is powered-up.
  }, (state) => {
    BackgroundGeolocation.start(function() {
    
    });
  });   
}

Here is the function where it sends Local Notification

onLocation(location) { console.log('LOCATION CHANGE DETECTED.');

Can you please tell me what am i missing. ?

Here is the complete file if you need to take a brief look. Click here to view : App.js

jnranawedo avatar Mar 13 '18 10:03 jnranawedo

console.log(‘- location, event: ‘, location.event, ‘, sample?’, location.sample);

christocracy avatar Mar 13 '18 10:03 christocracy

Here is the output to the above debug :

LOCATION CHANGE DETECTED.
- location, event:  undefined , sample? true

LOCATION CHANGE DETECTED.
- location, event:  motionchange , sample? undefined

So you mean that i need to execute my function if location.sample is set ?

jnranawedo avatar Mar 13 '18 10:03 jnranawedo

When the plugin is fetching the motionchange position or the method #getCurrentPosition is used, the plugin listens to multiple samples to choose the most accurate.

All of these samples are sent to the location event. People often use these to progressively update a position marker on a map.

If you don’t want to use them, ignore them.

On Tue, Mar 13, 2018 at 6:56 AM Jitendrasinh Rana [email protected] wrote:

Here is the output to the above debug :

LOCATION CHANGE DETECTED.

  • location, event: undefined , sample? true LOCATION CHANGE DETECTED.
  • location, event: motionchange , sample? undefined

So you mean that i need to execute my function if location.sample is set ?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/transistorsoft/react-native-background-geolocation/issues/431#issuecomment-372626039, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA6l0jiohhZrq918E3ffRaWTHDiYRpjks5td6XygaJpZM4Soc1z .

-- Snet form Gmail Mobile

christocracy avatar Mar 13 '18 11:03 christocracy