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

Editable timeout and new parameter

Open medvidekPanda opened this issue 3 years ago • 38 comments

Problem

There is no option to set custom timeout and setFastestInterval parameter.

Solution

  • Could you add possibility to add custom timeout value for setMaxWaitTime and setMaxWaitTime?
  • Could you add setFastestInterval with possibility custom value?

medvidekPanda avatar Sep 09 '21 05:09 medvidekPanda

This has been requested before, but I am reticent to include a configuration option for Android when an equivalent option does not exist for iOS. Is the distance filter option not sufficient for your needs?

diachedelic avatar Sep 09 '21 05:09 diachedelic

OK I didn't know that. But I need timeout, because I need request position periodically. For example every 30 seconds. I understand different options for different OS should be complicated. But in Cordova / Capacitor plugins it is normal. For my pour. iOS is not important for my purposes. I work on Android app only.

medvidekPanda avatar Sep 09 '21 06:09 medvidekPanda

I am sympathetic to your cause. Could you please explain to me your use case, and why a distance filter is not sufficient?

diachedelic avatar Sep 09 '21 07:09 diachedelic

Distance filter is not sufficient, because I need get location in long interval in some situation, for example every 30 seconds, but device is on one place. Yes I can make some workaround in app controler, but I think, get position from OS api is better, when API has this feature.

medvidekPanda avatar Sep 09 '21 07:09 medvidekPanda

Yes, but why do you need the location every 30 seconds if the devices has not moved? Is it just to trigger something in the UI?

diachedelic avatar Sep 09 '21 08:09 diachedelic

Exactly as you said. App runs on the foreground / background and every X seconds send location to server.

medvidekPanda avatar Sep 09 '21 10:09 medvidekPanda

Why does the server require location updates every X seconds, even if the location has not changed?

diachedelic avatar Sep 09 '21 23:09 diachedelic

It doesn't matter at all. I have such a request from a customer. He needs to be 100% sure that the device is in place or in motion at such a time and at such an interval. When the object moves 10 km per hour, it travels a different distance than it travels 100 km per hour.

medvidekPanda avatar Sep 10 '21 07:09 medvidekPanda

I see. The requests to the server are keeping the connection alive, so to speak.

diachedelic avatar Sep 10 '21 08:09 diachedelic

Would you be happy if the setting was defined in strings.xml, like these?

diachedelic avatar Sep 10 '21 08:09 diachedelic

I'm afraid not :-(. The requirement is to change the timeout from FE. So it can be up to 15 seconds or 60 seconds depending on the user.

medvidekPanda avatar Sep 10 '21 13:09 medvidekPanda

There are three methods on LocationRequest which you have mentioned:

  • setInterval
  • setFastestInterval
  • setMaxWaitTime

Are you looking to control every one of these?

There is also the option of pulling the Android source code into your own project. It is just two classes and a few imports. Then you can have as much control as you need.

diachedelic avatar Sep 15 '21 00:09 diachedelic

I would like a feature like this for this reason:

On my application i set distance filter to 5 meter and normally i receive a location with a speed value.

I also use this speed value to do things(example: more speed value = more volume, but it can be 'distribute more salt on the road' so if speed is 0, i must distribute 0 salt and the vehicle run at 10km/h i must distribute 1kg salt, at 20km/h 2kg salt ...)

But what happens if in less then 5 meter the vehicle stops to run? I doesn't receive any update and i continue to think that my car is in motion and i continue to distribute salt. A mount of salt :)

At this point i must control myself that the last update is old and reset my speed.

gine avatar Oct 15 '21 12:10 gine

@gine How do you handle the situation that:

  • The app is closed or killed?
  • The connection between the app and the salt distributor fails?

In both scenarios, location messages will not be received. Do you stop distributing salt when no messages appear for a given period?

diachedelic avatar Oct 18 '21 06:10 diachedelic

@diachedelic the salt distributor has a "stupid" PLC the try to connect to me(i am a server, yes it's strange.. can't explane now) every 100ms for N times and i must respond with phone status. If no response arrive, the plc change from manual mode to auto mode. At the moment i'm testing it with gps meter = 5 and it's impossible to get speed = 0.. i'm testisting realy now.

sure, i can put a timer in the app that each N ms look if i have a new gps data but it's better what we are asking and that you implement a new type of filter.

I will try with gps meter filter to 1m and i'll wtite what happen.. A lot of data drain a lot of cpu :(

gine avatar Oct 22 '21 14:10 gine

With 1mt filter work really better because the car breaking need at least 1 mt to stop the car but sometimes still happen

gine avatar Oct 22 '21 15:10 gine

@gine, I was intrigued by your idea in #41 to set the distance filter dynamically. I do not know if it would reduce energy consumption, but it might. What do you think of this as a solution?

diachedelic avatar Oct 25 '21 04:10 diachedelic

Hello,

This plugin works perfectly fine on both iOS and Android. However it drains battery very fast. My app requires user to have it's location tracked all the time (well almost all the time ... it's a delivery app).

I tried using stale position true and distance filter of 50m, but it had no impact on the battery usage.

My suggestion is to have the option to have the location checked every lets say 30 sec, then the service will go 'dormant' and not check for device location for the next 30 seconds. Might be stupid but I can't think of any other way I can save the battery usage.

Thank-you!

EDIT

I think on Android this could be achieved if if you change this line to accept an input, not a hard-codded value of '1000'.

Callan003 avatar Dec 10 '21 07:12 Callan003

I tried using stale position true and distance filter of 50m, but it had no impact on the battery usage.

That's a shame the distance filter does not help with battery drain. Was this the case on both iOS and Android? I think I have to accept that this plugin needs a setting which controls Android's setInterval. But I don't know how to help you with iOS.

On Android, it is also possible to use the PRIORITY_BALANCED_POWER_ACCURACY priority for coarser location updates, about 100m. I would be interested to know how using this priority instead affects battery usage on your device. Could you please see if that gives an improvement? It should be possible to just modify the file and rebuild.

diachedelic avatar Dec 20 '21 12:12 diachedelic

@gine, I was intrigued by your idea in #41 to set the distance filter dynamically. I do not know if it would reduce energy consumption, but it might. What do you think of this as a solution?

it can work.

gine avatar Jan 04 '22 14:01 gine

Any news on this matter?

josuelmm avatar Feb 09 '22 02:02 josuelmm

@josuelmm What is your use case?

diachedelic avatar Feb 09 '22 02:02 diachedelic

Being able to change the values of: setMaxWaitTime(1000); setInterval(1000);

From Ionic

josuelmm avatar Feb 09 '22 03:02 josuelmm

Hello Sir , i am not sure if you still need fix , i did the exact same thing as i needed the same thing as you xD

so , what you need to do is simple

in BackgroundGeolocationService.java Change locationRequest.setInterval(1000); to locationRequest.setInterval(30000);

and set config distanceFilter: 0

you will receive the location every 30 seconds even if you don't move :)

, i made pull request with editable interval from capacitor

https://github.com/Zack-Heisnberg/background-geolocation

Zack-Heisnberg avatar Feb 23 '22 00:02 Zack-Heisnberg

Hello Sir , i am not sure if you still need fix , i did the exact same thing as i needed the same thing as you xD

so , what you need to do is simple

in BackgroundGeolocationService.java Change locationRequest.setInterval(1000); to locationRequest.setInterval(30000);

and set config distanceFilter: 0

you will receive the location every 30 seconds even if you don't move :)

, i made pull request with editable interval from capacitor

https://github.com/Zack-Heisnberg/background-geolocation

Can you make a PR?

matudelatower avatar Apr 21 '22 10:04 matudelatower

Hello Sir , i am not sure if you still need fix , i did the exact same thing as i needed the same thing as you xD

so , what you need to do is simple

in BackgroundGeolocationService.java Change locationRequest.setInterval(1000); to locationRequest.setInterval(30000);

and set config distanceFilter: 0

you will receive the location every 30 seconds even if you don't move :)

, i made pull request with editable interval from capacitor

https://github.com/Zack-Heisnberg/background-geolocation

hi! is this fix applicable on android only?

indrapalijama avatar Apr 12 '23 09:04 indrapalijama

Hello Sir , i am not sure if you still need fix , i did the exact same thing as i needed the same thing as you xD so , what you need to do is simple in BackgroundGeolocationService.java Change locationRequest.setInterval(1000); to locationRequest.setInterval(30000); and set config distanceFilter: 0 you will receive the location every 30 seconds even if you don't move :) , i made pull request with editable interval from capacitor https://github.com/Zack-Heisnberg/background-geolocation

hi! is this fix applicable on android only?

yes, its only for android

matudelatower avatar Apr 12 '23 12:04 matudelatower

Hello Sir , i am not sure if you still need fix , i did the exact same thing as i needed the same thing as you xD so , what you need to do is simple in BackgroundGeolocationService.java Change locationRequest.setInterval(1000); to locationRequest.setInterval(30000); and set config distanceFilter: 0 you will receive the location every 30 seconds even if you don't move :) , i made pull request with editable interval from capacitor https://github.com/Zack-Heisnberg/background-geolocation

hi! is this fix applicable on android only?

yes, its only for android

i see, noob question : how can i install zack's forked repo? i tried using npm install but got failed

indrapalijama avatar Apr 13 '23 06:04 indrapalijama

Did you try npm install https://github.com/Zack-Heisnberg/background-geolocation? It worked for me.

diachedelic avatar Apr 13 '23 06:04 diachedelic

npm install https://github.com/Zack-Heisnberg/background-geolocation

still got the error dear sir, here's the error

indrapalijama avatar Apr 13 '23 06:04 indrapalijama