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

Emit position event only by the time that a distance change was made - not automatically after 5 seconds #162

Open
Taxi4you opened this issue Jun 24, 2019 · 5 comments

Comments

@Taxi4you
Copy link

Feature Request

Motivation Behind Feature

This is a must have feature. Save battery consuming, report about position changes to API only when there a significant change - instead of every 5 seconds.

Feature Description

The watchPosition method emits the success callback after every 5 seconds (if there no errors). This is bad. It has to emit the event only when the user actually moves - in order to save battery and report to remote APIs only when needed.

Alternatives or Workarounds

I am using some wrapper of the service, only when there some significant distance between previous position that was saved I send it to the DB.
I defined by my own the minimal distance in meters in order to consider a change.
This is not a good way of working. This plugin should emit only when there was a change in position and it should be setted for what is change in position or not.

@breautek
Copy link
Contributor

Just posting some relevant information for this feature request.

Currently not configurable but this is already done on iOS.

Note distanceFilter which I believe is in meters.

if (enableHighAccuracy) {
__highAccuracyEnabled = YES;
// Set distance filter to 5 for a high accuracy. Setting it to "kCLDistanceFilterNone" could provide a
// higher accuracy, but it's also just spamming the callback with useless reports which drain the battery.
self.locationManager.distanceFilter = 5;
// Set desired accuracy to Best.
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
} else {
__highAccuracyEnabled = NO;
self.locationManager.distanceFilter = 10;
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
}

As for Android, this plugin uses the webview geolocation implementation, which doesn't have a configurable distance filter as far as I can tell. In order to accomplish this, I think the plugin will to use the android location manager directly instead of relying on the browser implementation.

@Taxi4you
Copy link
Author

Thanks for your reply.
How to enable this for iOS, if I set options object to be:

{
  distanceFilter: NUMBER
}

Is this the proper way?

**

For Android, when will this be available, is there any roadmap for doing so?

@breautek
Copy link
Contributor

How to enable this for iOS

The plugin has the value hard coded to be 5 meters when high accuracy is enabled, or 10 meters otherwise.

For Android, when will this be available, is there any roadmap for doing so?

Sorry, I'm not the person that can answer that question. Obviously moving from the browser implementation to a custom implementation that uses Android's geolocation APIs directly is a significant change...

@breautek
Copy link
Contributor

breautek commented Jun 24, 2019

For the record, I'm having a quick scan through Android Location documentation and it doesn't look like they have a distance filter concept either. Their battery saving recommendations makes no mention of a distance filter and their API reference seems to lack a distance filter setting. So I'm not sure if this is even possible on Android. Distance filter might be an iOS concept only.

Personally I think the distanceFilter for iOS should be configurable. The defaults can be left as is if not explicitly set by the app. For android, the API/config properties would have to be ignored as Android seems to have a different philosophy on achieving conservative battery status when using geolocation.

@ctcampbell
Copy link

ctcampbell commented Aug 28, 2019

I agree on letting your users choose how they want the library to work, not forcing them to make changes to your code if they need higher accuracy than 5m changes. At the least this should be documented.

I also found evidence that distanceFilter has no direct impact on battery life at https://stackoverflow.com/questions/5490707/does-cllocationmanager-distancefilter-do-anything-to-conserve-power

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

No branches or pull requests

3 participants