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

Editable timeout and new parameter #34

Open
medvidekPanda opened this issue Sep 9, 2021 · 38 comments
Open

Editable timeout and new parameter #34

medvidekPanda opened this issue Sep 9, 2021 · 38 comments

Comments

@medvidekPanda
Copy link

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?
@diachedelic
Copy link
Collaborator

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?

@medvidekPanda
Copy link
Author

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.

@diachedelic
Copy link
Collaborator

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

@medvidekPanda
Copy link
Author

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.

@diachedelic
Copy link
Collaborator

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?

@medvidekPanda
Copy link
Author

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

@diachedelic
Copy link
Collaborator

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

@medvidekPanda
Copy link
Author

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.

@diachedelic
Copy link
Collaborator

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

@diachedelic
Copy link
Collaborator

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

@medvidekPanda
Copy link
Author

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.

@diachedelic
Copy link
Collaborator

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.

@gine
Copy link

gine commented Oct 15, 2021

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.

@diachedelic
Copy link
Collaborator

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

@gine
Copy link

gine commented Oct 22, 2021

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

gine commented Oct 22, 2021

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

@diachedelic
Copy link
Collaborator

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

@Callan003
Copy link

Callan003 commented Dec 10, 2021

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

@diachedelic
Copy link
Collaborator

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

gine commented Jan 4, 2022

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

@josuelmm
Copy link

josuelmm commented Feb 9, 2022

Any news on this matter?

@diachedelic
Copy link
Collaborator

@josuelmm What is your use case?

@josuelmm
Copy link

josuelmm commented Feb 9, 2022

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

From Ionic

@Zack-Heisnberg
Copy link

Zack-Heisnberg commented Feb 23, 2022

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

@matudelatower
Copy link

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?

@indrapalijama
Copy link

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?

@matudelatower
Copy link

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

@indrapalijama
Copy link

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

@diachedelic
Copy link
Collaborator

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

@indrapalijama
Copy link

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

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

@diachedelic
Copy link
Collaborator

Did you first remove the @capacity-community/background-geolocation package from your package.json? It can not coexist with Zack's fork.

@indrapalijama
Copy link

Did you first remove the @capacity-community/background-geolocation package from your package.json? It can not coexist with Zack's fork.

yes, i'm well aware of it, here's the proof

@DocBO
Copy link

DocBO commented Dec 21, 2023

If you stumble across this issue also, consider to change the relevant lines in your local folder node_modules/..../BackgroundGelolocationService.java before building again according to the new android API:

LocationRequest.Builder locationRequestBuilder = new LocationRequest.Builder(30000);
locationRequestBuilder.setPriority(Priority.PRIORITY_BALANCED_POWER_ACCURACY);
locationRequestBuilder.setIntervalMillis(30000);
locationRequestBuilder.setMaxUpdateDelayMillis(30000);
locationRequestBuilder.setMinUpdateDistanceMeters(distanceFilter);

This seems to result in a reasonable background action (I have not tested the battery drain over time).

@1MarcoP
Copy link

1MarcoP commented Dec 22, 2023

Hi, I just stumbled across this plugin which works really well.

For my use case, I want to periodically check the location of some users while they approach a certain destination and sync it (if the location changed) with the backend for some dispatcher to be informed. I want this to be as energy efficient as possible, as I often only have to request the location every few minutes.

So far I read that the iOS part is making difficulties regarding the timeout parameter.

I have little knowledge of iOS and swift, but just tried out if a native timer can be used.

if let interval = call.getInt("interval") {
  manager.startUpdatingLocation()
  Timer.scheduledTimer(withTimeInterval: TimeInterval(interval), repeats: true) { _ in
    manager.requestLocation()
  }
}

However, inside locationManager/didUpdateLocations I had to call locationManager.stopUpdatingLocation(). I thought this might be a big problem as the app won't send updates while in background, but in my tests it continued requesting the location every n seconds and the native timer did work surprisingly well.

As I stated, I don't have much knowledge about swift, but would like to understand what the biggest concern is?
Would the native timer actually be more energy efficient?

@diachedelic
Copy link
Collaborator

I'm surprised that works in the background. What interval values did you try? Did the status bar turn blue whilst the app was in the background?

If this approach works in the background, turns out to be energy efficient, and gives accurate results, I will add an "interval" option. However,

@1MarcoP
Copy link

1MarcoP commented Jan 18, 2024

Hi, sorry for the late reply. I didn't have access to a Mac for building iOS, during the last days.

I tried 10 seconds, 30 seconds, 1 minute, 5 minutes and 15 minutes.
I let the 15 minute one run for about 2h 30min in the background.

However, the status bar turned blue in the beginning, but afterwards it only turned blue again when the GPS tracking was done (every n seconds). Therefore, I am not sure if the app could be killed in the background when the phone is under a heavy load?

@GeekAliAkbar
Copy link

After adding this

If you stumble across this issue also, consider to change the relevant lines in your local folder node_modules/..../BackgroundGelolocationService.java before building again according to the new android API:

LocationRequest.Builder locationRequestBuilder = new LocationRequest.Builder(30000); locationRequestBuilder.setPriority(Priority.PRIORITY_BALANCED_POWER_ACCURACY); locationRequestBuilder.setIntervalMillis(30000); locationRequestBuilder.setMaxUpdateDelayMillis(30000); locationRequestBuilder.setMinUpdateDistanceMeters(distanceFilter);

This seems to result in a reasonable background action (I have not tested the battery drain over time).

I tried above solution and got this error
watcher.locationRequest = locationRequest; ^ symbol: variable locationRequest location: class BackgroundGeolocationService.LocalBinder

Any idea how to solve this

@DocBO
Copy link

DocBO commented Jan 18, 2024

Hi, I forgot this line at the end (again, according to the new android api):

LocationRequest locationRequest = locationRequestBuilder.build();

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