I have an app that track location using a location manager. I want to log a location when a user moved 100 feet, so I set up the listener to request updates for 100 feet and pass in a time of 30 seconds. I can see my gps icon blinking every 30 seconds so it is requesting a location. However, if I am it a building with a poor signal it will try CONSTANTLY to poll a gps location, so the signal never stops blinking, which drains the battery in a hurry. Is there a way to NOT poll for a gps location if it cannot get a signal right away? I tried passing in a large value for time (say 30 minutes) but then my gps only polls every 30 minutes, regardless of the distance I moved.
You don't seem to understand how GPS works. You don't poll GPS. It requires you to continually track signals from a set of satellites. You don't poll once and ignore it- you continually track the signals. In fact, it can take 10s of seconds to a few minutes to lock on to enough signals to triangulate your location. So you can't just poll every 30 seconds or so.
If you want to use low battery, use network location and sacrifice accuracy. If you want to know accurately when someone has moved 100 feet, you have to use GPS and take the hit. You can't get both.
Related
I'm using Fused Location Provider library in android. It is working perfectly fine. But I've an issue with it, it returns location updates in 5 sec minimum.
I've tried every thing like setting minimum updates time to 1 millisecond, and distance to 0.01 meter and Priority to PRIORITY_HIGH_ACCURACY
My code :
locationrequest.setInterval(1); // 1 milliseconds
locationrequest.setSmallestDisplacement(0.01f); // 0.01 meters locationrequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
But no use, still minimum time between two successive location updates is 5 seconds.
My Questions is : Is there any way to decrease location updates time to 5 milliSeconds ?
-> I need location updates for only 10 minutes, So no issue with the high battery consumption.
-> I need any way (possible): Is there any external hardware available, which connects via Bluetooth and send location updates upto that level ?
Edits:
Let me ask you a different question :
What can be the minimum possible time for location updates and how to achieve that ?
Let's say i want to track a car, which is moving with the speed of 400 KM/h, means 5 meter in about 50ms. So can you suggest any better way to track this car ?
The precision and accuracy of location-sensing hardware (GPS, AGPS, etc.) means that getting updates more frequently than every few seconds isn't likely to provide meaningful results. In fact, technology like the Fused Location Provider is likely to prioritize getting more accurate results rather than providing results every few hundred milliseconds.
In addition to that, the battery drain from getting updates multiple times a second is likely to be very significant.
All that said. The way to get every update that your location-sensing hardware is receiving is to set the location update interval and minimum displacement to zero, and to prioritize accuracy.
locationrequest.setInterval(0); // No delay.
// locationrequest.setSmallestDisplacement(0); // This is the default.
locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Note that this will give you every update, but depending on the hardware limitations, and potentially the Fused Location Provider implementation, there's no guarantee this will be any faster than the 5s frequency you've found so far.
I am developing an app, where I need (GPS) coordinates every couple of seconds, unfortunately the GPS uses a lot of battery.
Is it possible to get a good estimated position (including altitude) based on the last GPS position(s) and motion sensors from an Android smartphone, for let's say 1 minute?
What algorithms would I need to look into?
This does not work with GPS.
The GPS chip has to track the sattelites all the time, so it makes no difference for battery consumption if you get once a minute or once a second.
Things changes when you only need a position evry 5 minutes, then it could make sense to stop location service, and restart again. (but even that is only a vague estimation).
Finally you have to measure which intervall really saves battery.
bye the way: i can record 8 hours of gps with one fix per second, on iphone 4
I developed an application that fetches GPS location. I specified minTime as 20 seconds and minDistance as 1 meter in requestLocationUpdate method. But still i am getting location in 2-3 seconds interval and sometimes it takes more than one minute. Can i get location at particular time interval and within 1 minute?
Please Help.
Thanks in advance.
Can i get location at particular time interval and within 1 minute?
Not necessarily.
First, you set minDistance to 1 meter. Try using 0.
Second, you are limited by how frequently the GPS radio actually gets fixes, which will be based on environmental factors and is outside of your control.
Third, minTime is a hint, as the documentation explains. Hence, you may get fixes more frequently than it, or less frequently. For a minTime of 20 seconds, it is unlikely that Android will power down the GPS radio between fixes, and so I suspect that value is not helping you any.
I am experimenting with Androids location updates. The requestLocationUpdates is responsible for providing the updates. With the following code:
locationManager.requestLocationUpdates(provider, 300000, 10, this);
I am only supposed to receive updates 5 minutes and 10 meters apart. But the updates just keep coming in seconds apart and even when I am sitting still.
GPS is the provider I am using.
I need to space the updates out. What can I try?
The 10m is too small - I would increase that. GPS accuracy isn't great, and so every time it senses a small difference you will get another location. I'd bump it up to 100m and I expect you will then get a sensible number of locations coming through.
If you do want it more specific, then you'll need to handle the volume as more accurate means more volume.
Hers what i'd do:
First of all I check what providers are enabled. Some may be disabled on the device, some may be disabled in application manifest.
If any provider is available I start location listeners and timeout timer. It's 20 seconds in my example, may not be enough for GPS so you can enlarge it.
If I get update from location listener I use the provided value. I stop listeners and timer.
If I don't get any updates and timer elapses I have to use last known values.
I grab last known values from available providers and choose the most recent of them.
The 10m is too small for a GPS reading, try 100m. You'll also have issues with power saving mode, and app battery optimisation on most Android phones.
Android 10 and above has very strict background location updates, and may kill apps that run in the background. Later versions will also remove apps that have not be used recently.
I'm trying to limit my program to take location updates every 10 seconds instead of constant updates in order to reduce battery drain. This works fine when i'm debugging indoors and the signal is weak (i.e. the GPS icon flashes), but if the phone gets a proper fix (i.e. the GPS icon is static) the update interval increases to roughly a second.
I know that the code mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateInterval*1000, 0, this); will not force the GPS to take updates exactly at the given interval, but in my opinion it shouldn't depend on the strength of the signal and fluctuate that much.
Any ideas?
UPDATE: see comment
I suspect that the GPS radio works in a manner where either it's connected to GPS satellites or it's not. When it's connected, the Android SDK sends you updates as frequently as they're available from the GPS hardware. When it doesn't have a full GPS connection it falls back to sending AGPS updates according to what you've requested.
If you only want updates every 10 seconds, you should save the last received Location's time value in your listener, and when you receive a new Location check its time against the old value; ignore it if it's too frequent (or do something smarter like checking the accuracy and replacing the old value, etc).
Maybe it works slower because you are debugging, but not because your signal is weak! Try to make tests with disconnected debugger indoors...