cordova-background-geolocation-SampleApp
cordova-background-geolocation-SampleApp copied to clipboard
Very large GPS position variation
Good Morning, I'm using in my app the cordova-plugin-googlemaps along with background-geolocation. When I try to use background-geolocation positioning to get a route next to the google API, it often has a very large variation and ends up tracing the route on the way to the opposite side. Using the sample it always stays inside the track where I'm walking. My configuration looks like this:
_backgroundGeolocationInstance.configure ({
// Geolocation config
DesiredAccuracy: 0,
DistanceFilter: 0,
DisableElasticity: true,
GeofenceProximityRadius: 1000,
LocationTimeout: 60,
LocationUpdateInterval: 1000,
FastestLocationUpdateInterval: 1000,
Defer Time: 0,
// Activity Recognition config
StopTimeout: 5,
ActivityType: 'AutomotiveNavigation',
ActivityRecognitionInterval: 1000,
TriggerActivities: 'in_vehicle',
StopOnTerminate: true,
StartOnBoot: true,
HeartbeatInterval: 60,
ForegroundService: true,
StationaryRadius: 20,
// Application config
Debug: false
}
Is there anything I can do to improve accuracy and it only returns me to the position within the path I'm actually in at the moment?
Well, for one thing, all your config params are incorrectly capitalized. Your entire config is essentially invalid.
eg: DesiredAccuracy
!= desiredAccuracy
.
Where did you get the idea to do that?
Defer Time
?? You can't have spaces in a JSON key without ""
. That should be generating a syntax error.
Excuse. I am from Brazil and these errors pointed out because of Google Translate.
_backgroundGeolocationInstance.configure({
// Geolocation config
desiredAccuracy: 0,
distanceFilter: 0,
disableElasticity : true,
geofenceProximityRadius : 1000,
locationTimeout : 60,
locationUpdateInterval: 1000,
fastestLocationUpdateInterval: 1000,
deferTime: 0,
// Activity Recognition config
stopTimeout : 5,
activityType: 'AutomotiveNavigation',
activityRecognitionInterval: 1000,
triggerActivities:'in_vehicle',
stopOnTerminate: true,
startOnBoot: true,
heartbeatInterval : 60,
foregroundService: true,
stationaryRadius: 20,
//desiredOdometerAccuracy: 10,
// Application config
debug: false
}
If the plugin is working fine without cordova-plugin-googlemaps
, the problem must be with cordova-plugin-googlemaps
Actually my problem is with the variation of the Lat and Lng I get. Even stopped.
Anyway, thanks for the reply. I'll look elsewhere.
I have the same problem and no solution, I have some variations on my ponga I think this happens when the cell phone has a low signal and it does not know the correctly position
@danielaraujo do you find a solution to reduce the variations on your gps points
The only thing you can do is set desiredAccuracy: 0
. Everything else depends upon device settings and network environment.
@christocrazy do u know some algorithm to apply, as you know sometimes the gps fails and register bad location. I would know if you know some solution to remove or detect which of that point are unusual on my tracking path
This s the purpose of location attribute accuracy
Any location problems are due to device and/or network environment.
Here's a ~300km round trip with my Google Pixel last weekend: not a single poor location.
I created an algorithm to solve this issue -- I might need to tweak the maximum accepted delta but here is what I did:
- I modified onLocation() like so:
onLocation(location: any, taskId: any) {
if (this.lastLocation != null) {
if (this.locationIsAccurate(location, this.lastLocation)) {
this.continueOnLocation(location, taskId);
}
}
else {
this.continueOnLocation(location, taskId);
}
}
- I moved everything that used to be in onLocation() to continueOnLocation()
continueOnLocation(location: any, taskId: any) {
console.log('[js] location: ', location);
let bgGeo = this.bgService.getPlugin();
this.setCenter(location);
if (!location.sample) {
this.zone.run(() => {
// Convert meters -> km -> round nearest hundredth -> fix float xxx.x
this.state.odometer = parseFloat((Math.round((location.odometer / 1000) * 10) / 10).toString()).toFixed(1);
});
}
bgGeo.finish(taskId);
}
- I created the locationIsAccurate() method.
locationIsAccurate(location: any, lastLocation: any) {
let maxDelta = 0.0001;
let deltaLatitude = Math.abs(
(location.coords.latitude - this.lastLocation.coords.latitude)
)
let deltaLongitude = Math.abs(
(location.coords.longitude - this.lastLocation.coords.longitude)
)
//CHECK IF DISTANCE IS TOO FAR, ie PREVENT WEIRD LINES ON MAP
console.log("Comparing this location and last location:");
console.log("Current Latitude: " + location.coords.latitude);
console.log("Current Longitude: " + location.coords.longitude)
console.log("Last Latitude: " + this.lastLocation.coords.latitude);
console.log("Last Longitude: " + this.lastLocation.coords.longitude);
console.log("Delta Latitude: " + deltaLatitude);
console.log("Delta Longitude: " + deltaLongitude);
if (
(
(deltaLatitude < maxDelta) &&
(deltaLongitude < maxDelta))
) {
return true;
} else {
console.log("Location is not accurate: ignoring coordinate");
this.polyline.getPath().pop();
return false;
}
}
Why are you not simply checking the location accuracy? "Weird" locations likely have a very low accuracy (e.g. > 1000)
I always have my accuracy on -1 when I encounter the issue.
I'm not talking about desiredAccuracy, I said location accuracy.
my accuracy it is always in 3.0 to 4.0
There is nothing to complain about with locations having accuracy 3-5 meters. Those are perfectly fine locations
Your plugin is amazing and I would give up entirely on using Ionic if it didn't exist. So thank you. I was just sharing my solution.
It's available for React Native and pure native apps too.
so i don't know what is wrong or what is happening
my points look like this, all in red are bad locations i solve this a litle bit adding a request to api of google snap to roads
And what is the corresponding location accuracy for "locations in red"? There's no way it's 3-5 meters.
There's nothing to be done in the plugin to solve that. It's due to the device and/or network environment. It could be power-saving mode on the device being engaged.
thanks @christocracy ur plugin is perfect i just wanted to know if there was something to do for fix that.
- Check Settings->Location (ensure "High Accuracy")
- Check Settings->Battery-> Power Saving
- Ensure wifi enabled
my acurracy form some points in red is to accuracy";d:16.699999999999999.
so the value of accurracy means that if the value is high like this accuracy";d:16.699999999999999 i could consider it as a bad point.
accuracy > 10
typically means the location did not come from GPS; it came from Wifi instead.
Personally, I wouldn't call a location with accuracy 17
bad. I'd call a location with accuracy > 200
"bad"
@christocracy I'm building something that will be used indoors a lot. So instead of comparing the actual latitude and longitude, I see now I could've just checked that the accuracy is within 5 meters before adding a breadcrumb. Oh well, I guess it's the same thing.
Indoors, the best accuracy you'll get is 40
meters. GPS is impossible indoors.
thanks @christocracy for your help.
I mean it still depends on what type of roof you're under, right? It seems to work fine for me in most buildings.
GPS receiver on mobile devices is a microwave radio receiver. It doesn't take much to block a low amplitude / high frequency signal from space.
Put a GPS Test app on your device an see for yourself how many satellites your device "locks-on to".
Maybe if you're under a grass roof, you might get a signal. Concrete or metal? forget it.