Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very large GPS position variation #80

Open
danielaraujo opened this issue Jul 31, 2017 · 33 comments
Open

Very large GPS position variation #80

danielaraujo opened this issue Jul 31, 2017 · 33 comments

Comments

@danielaraujo
Copy link

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?

@christocracy
Copy link
Member

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.

@danielaraujo
Copy link
Author

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
		        

			}

@christocracy
Copy link
Member

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

@danielaraujo
Copy link
Author

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.

@xhava
Copy link

xhava commented Aug 28, 2017

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
Copy link

xhava commented Aug 31, 2017

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

@christocracy
Copy link
Member

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

@xhava
Copy link

xhava commented Sep 4, 2017

@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

@christocracy
Copy link
Member

This s the purpose of location attribute accuracy

@christocracy
Copy link
Member

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.

@arapocket
Copy link

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;
    }
  }

@christocracy
Copy link
Member

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

@arapocket
Copy link

arapocket commented Sep 5, 2017

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

@christocracy
Copy link
Member

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

@xhava
Copy link

xhava commented Sep 5, 2017

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

@christocracy
Copy link
Member

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

@arapocket
Copy link

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.

@christocracy
Copy link
Member

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

@xhava
Copy link

xhava commented Sep 5, 2017

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

@christocracy
Copy link
Member

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.

@xhava
Copy link

xhava commented Sep 5, 2017

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

@christocracy
Copy link
Member

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

@xhava
Copy link

xhava commented Sep 5, 2017

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.

@christocracy
Copy link
Member

christocracy commented Sep 5, 2017

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"

@arapocket
Copy link

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

@christocracy
Copy link
Member

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

@xhava
Copy link

xhava commented Sep 5, 2017

thanks @christocracy for your help.

@arapocket
Copy link

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

@christocracy
Copy link
Member

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
Copy link
Member

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

@arapocket
Copy link

To be fair, I tried it in a very hipster building in LA that I work at. The roof might be made of recycled cereal boxes...

@christocracy
Copy link
Member

Being next to windows will help with "seeing" GPS satellites.

@richrichDev
Copy link

to solve this issue , in ionic if you are using javascript google maps API in console.cloud.google.com, after you get the locations use Snap to roads API in console.cloud.google.com to draw the real path and then you will get the real path on the route and you dont get points outside the path like you had.
but Still you have a problem that :
if someone is running in a football field let's say , if you use snap to roads API the path will be drawn on the routes outside not inside the field , i dont know if there is a solution for this ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants