background-geolocation
background-geolocation copied to clipboard
Editable timeout and new parameter
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?
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?
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.
I am sympathetic to your cause. Could you please explain to me your use case, and why a distance filter is not sufficient?
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.
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?
Exactly as you said. App runs on the foreground / background and every X seconds send location to server.
Why does the server require location updates every X seconds, even if the location has not changed?
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.
I see. The requests to the server are keeping the connection alive, so to speak.
Would you be happy if the setting was defined in strings.xml
, like these?
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.
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.
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 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 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 :(
With 1mt filter work really better because the car breaking need at least 1 mt to stop the car but sometimes still happen
@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?
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'.
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.
@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.
Any news on this matter?
@josuelmm What is your use case?
Being able to change the values of: setMaxWaitTime(1000); setInterval(1000);
From Ionic
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
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?
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?
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
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
Did you try npm install https://github.com/Zack-Heisnberg/background-geolocation
? It worked for me.
npm install https://github.com/Zack-Heisnberg/background-geolocation
still got the error dear sir, here's the error