cordova-plugin-geolocation icon indicating copy to clipboard operation
cordova-plugin-geolocation copied to clipboard

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

Open Taxi4you opened this issue 5 years ago • 5 comments

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.

Taxi4you avatar Jun 24 '19 14:06 Taxi4you

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.

https://github.com/apache/cordova-plugin-geolocation/blob/6be29f2cdcfeae5ca8ab35b4fa6d60a256276df6/src/ios/CDVLocation.m#L140-L151

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.

breautek avatar Jun 24 '19 14:06 breautek

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?

Taxi4you avatar Jun 24 '19 15:06 Taxi4you

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 avatar Jun 24 '19 15:06 breautek

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.

breautek avatar Jun 24 '19 15:06 breautek

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

ctcampbell avatar Aug 28 '19 16:08 ctcampbell