why getValidLocations() method gives duplicate data ?
See original GitHub issueI am using getValidLocations() method for retrieved stored location and push to server. after pushed i used deleteAllLocations() method for delete stored locations.
But many times getValidLocations() method gives me duplicate data , i think its due to plugin updates location two times at same time.
Your Environment
-
Plugin version: 2.3.5
-
Platform: iOS
-
OS version: 10.2.1
-
Device manufacturer and model: iPhone 5s
-
Cordova version (
cordova -v
): 8.0.0 -
Cordova platform version (
cordova platform ls
): 4.5.4 -
Plugin configuration options:
let config = { desiredAccuracy: 0, stationaryRadius: 50, distanceFilter: 200, notificationTitle: 'XYZ', notificationText: 'ENABLED', foregroundService: true, debug: true, locationProvider: 1, interval: 120000, fastestInterval: 120000, url: 'http://....', httpHeaders: { "Content-Type": "application/json" }, postTemplate: { "UserId": this.UserId, "LocationData": [ { "Lat": this.lat, "Long": this.lng, "Date": this.cuuDate, "BatteryPerc": this.batteryLevel } ] }, method: 'POST', autoSync: true, saveBatteryOnBackground: false, stopOnTerminate: false, startOnBoot: true };
-
Link to your project:
Context
getValidLocations() method gives duplicate entry.
Expected Behavior
i think , its due to plugin updates two or three times at same time
Actual Behavior
Possible Fix
Steps to Reproduce
Context
Debug logs
My Code is Below… ` startBackgroundLocation() {
this.UserId = 4
let config = {
desiredAccuracy: 0, stationaryRadius: 50, distanceFilter: 200, notificationTitle: ‘XYZ’, notificationText: ‘ENABLED’, foregroundService: true, debug: true, locationProvider: 1, interval: 120000, fastestInterval: 120000, url: ‘http://…’, httpHeaders: { “Content-Type”: “application/json” }, postTemplate: { “UserId”: this.UserId, “LocationData”: [ { “Lat”: this.lat, “Long”: this.lng, “Date”: this.cuuDate, “BatteryPerc”: this.batteryLevel } ] }, method: ‘POST’, autoSync: true, saveBatteryOnBackground: false, stopOnTerminate: false, startOnBoot: true }; this.backgroundGeolocation.configure(config).subscribe((location) => {
console.log('configuration: '+JSON.stringify(location));
console.log('Lat: '+location.latitude + ' :: '+location.longitude );
this.lat = location.latitude;
this.lng = location.longitude;
this.cuuDate = new Date();
this.cuuDate = moment(this.cuuDate).format('YYYY-MM-DDTHH:mm:ss');
console.log('current date and time : '+this.cuuDate);
const subscription = this.batteryStatus.onChange().subscribe(status => {
console.log(status.level, status.isPlugged);
this.batteryLevel = status.level;
});
if( this.httpService.isOnline() ) {
this.arrLocations = [];
// this.arrLocations = this.dbHandlerProvider.get_location();
this.backgroundGeolocation.getValidLocations().then(res=> {
// this.arrLocations = res;
console.log('Background getValidLocations: '+JSON.stringify(res));
for(let i=0; i<res.length; i++) {
var millisec = new Date(res[i].time);
var milliInDate = moment(millisec).format('YYYY-MM-DDTHH:mm:ss');
if(this.arrLocations.indexOf(res[i].latitude) != -1 && this.arrLocations.indexOf(res[i].longitude) != -1 && this.arrLocations.indexOf(res[i].milliInDate) != -1 ) {
} else {
this.arrLocations.push({
Lat: res[i].latitude,
Long: res[i].longitude,
Date: milliInDate,
BatteryPerc: this.batteryLevel
});
}
}
setTimeout(()=> {
console.log('Back Location Data: '+JSON.stringify(this.arrLocations));
this.serverPush.pushPosition({
UserId: this.UserId,
LocationData: this.arrLocations
});
},2000);
});
} else {
// this.dbHandlerProvider.add_location(this.lat,this.lng,this.cuuDate,11);
}
this.backgroundGeolocation.finish();
}, (err) => {
console.log(err);
});
this.backgroundGeolocation.start();
}`
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (5 by maintainers)
Top GitHub Comments
i am getting all stored location in the time of interval and delete records after pushed to server. but all time , i get duplicate entries 3-4 times.
please check my logs below
[{“provider”:“fused”,“time”:1528714195154,“latitude”:23.0401284,“longitude”:72.5188049,“accuracy”:30.132999420166016,“locationProvider”:1,“locationId”:4}]
[{“provider”:“fused”,“time”:1528714195154,“latitude”:23.0401284,“longitude”:72.5188049,“accuracy”:30.132999420166016,“locationProvider”:1,“locationId”:4}]
[{“provider”:“fused”,“time”:1528714195154,“latitude”:23.0401284,“longitude”:72.5188049,“accuracy”:30.132999420166016,“locationProvider”:1,“locationId”:4}]
This issue has been automatically closed, because it has not had recent activity. If you believe this issue shouldn’t be closed, please reopen or write down a comment requesting issue reopening with explanation why you think it’s important. Thank you for your contributions.