cordova-background-geolocation-SampleApp icon indicating copy to clipboard operation
cordova-background-geolocation-SampleApp copied to clipboard

Very large GPS position variation

Open danielaraujo opened this issue 7 years ago • 33 comments

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?

danielaraujo avatar Jul 31 '17 13:07 danielaraujo

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.

christocracy avatar Jul 31 '17 14:07 christocracy

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
		        

			}

danielaraujo avatar Jul 31 '17 14:07 danielaraujo

If the plugin is working fine without cordova-plugin-googlemaps, the problem must be with cordova-plugin-googlemaps

christocracy avatar Jul 31 '17 14:07 christocracy

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.

danielaraujo avatar Jul 31 '17 15:07 danielaraujo

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

xhava avatar Aug 28 '17 09:08 xhava

@danielaraujo do you find a solution to reduce the variations on your gps points

xhava avatar Aug 31 '17 05:08 xhava

The only thing you can do is set desiredAccuracy: 0. Everything else depends upon device settings and network environment.

christocracy avatar Aug 31 '17 06:08 christocracy

@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

xhava avatar Sep 04 '17 00:09 xhava

This s the purpose of location attribute accuracy

christocracy avatar Sep 04 '17 01:09 christocracy

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.

christocracy avatar Sep 05 '17 14:09 christocracy

I created an algorithm to solve this issue -- I might need to tweak the maximum accepted delta but here is what I did:

  1. 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);
    }
  }
  1. 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);
  }
  1. 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;
    }
  }

arapocket avatar Sep 05 '17 18:09 arapocket

Why are you not simply checking the location accuracy? "Weird" locations likely have a very low accuracy (e.g. > 1000)

christocracy avatar Sep 05 '17 18:09 christocracy

I always have my accuracy on -1 when I encounter the issue.

arapocket avatar Sep 05 '17 19:09 arapocket

I'm not talking about desiredAccuracy, I said location accuracy.

christocracy avatar Sep 05 '17 19:09 christocracy

my accuracy it is always in 3.0 to 4.0 captura de pantalla 2017-09-05 a la s 14 05 24

xhava avatar Sep 05 '17 19:09 xhava

There is nothing to complain about with locations having accuracy 3-5 meters. Those are perfectly fine locations

christocracy avatar Sep 05 '17 19:09 christocracy

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.

arapocket avatar Sep 05 '17 19:09 arapocket

It's available for React Native and pure native apps too.

christocracy avatar Sep 05 '17 19:09 christocracy

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

captura de pantalla 2017-09-03 a la s 21 58 21

xhava avatar Sep 05 '17 19:09 xhava

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.

christocracy avatar Sep 05 '17 19:09 christocracy

thanks @christocracy ur plugin is perfect i just wanted to know if there was something to do for fix that.

xhava avatar Sep 05 '17 19:09 xhava

  • Check Settings->Location (ensure "High Accuracy")
  • Check Settings->Battery-> Power Saving
  • Ensure wifi enabled

christocracy avatar Sep 05 '17 19:09 christocracy

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.

xhava avatar Sep 05 '17 19:09 xhava

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 avatar Sep 05 '17 19:09 christocracy

@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.

arapocket avatar Sep 05 '17 19:09 arapocket

Indoors, the best accuracy you'll get is 40 meters. GPS is impossible indoors.

christocracy avatar Sep 05 '17 19:09 christocracy

thanks @christocracy for your help.

xhava avatar Sep 05 '17 19:09 xhava

I mean it still depends on what type of roof you're under, right? It seems to work fine for me in most buildings.

arapocket avatar Sep 05 '17 19:09 arapocket

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".

christocracy avatar Sep 05 '17 19:09 christocracy

Maybe if you're under a grass roof, you might get a signal. Concrete or metal? forget it.

christocracy avatar Sep 05 '17 19:09 christocracy