Fused location API gives highly inaccurate location after closing google maps - android

Our application uses Google Fused location API to receive location updates every 3 minutes.
The location request settings are as follows –
Interval – 3min
Fastest interval – 1 min
Priority - PRIORITY_BALANCED_POWER_ACCURACY
In a normal running scenario, the location updates are received properly and the location accuracy is pretty good (around 20-25 m).
When the Maps application is opened, it received GPS location, and therefore our application also starts receiving location updates, which are basically from the GPS transceiver (I know this as the subsequent location updates have a speed and altitude value as well).
Problem occurs when the Maps application is now closed. Our application receives location updates, but the location coordinates do not change and every subsequent update received has a higher accuracy value. The updates may go up to even 1000m of accuracy and no accurate location are received. Opening the maps application again will make our application receive accurate and updated locations once again.
This problem can also be device specific as I saw this problem on a Motorola Moto G and not on my other Samsung or Karbonn phones.

In my experience, setting the priority to PRIORITY_BALANCED_POWER_ACCURACY never gets positions from the GPS, unless other app is using it. That's the same behaviour that you are finding in your app (in your case you only get GPS positioning when Maps is open), and that seems to be the general behaviour (see Does PRIORITY_BALANCED_POWER_ACCURACY exclude the GPS provider?).
I haven't found any official documentation to background this so I think that it may be device-dependant. In my tests, whenever I need GPS positioning I need to change the priority to PRIORITY_HIGH_ACCURACY.
Anyway, there is a known issue (57707) that is showing in some devices that causes the location provider to stop receiving position updates when set in PRIORITY_BALANCED_POWER_ACCURACY until the device is restarted.

Related

Android GPS is not updating location at high altitude inside aircraft

I am building an application for Android devices for skydivers to log location data during a skydive.
I have set the app up to record the device GPS location every 5 seconds in a foreground service. It seems to be working fine until the user is inside an aircraft, at which point the location may no longer update, or update very infrequently. Location updates will resume when the user has deployed their parachute.
The aircraft is a Cessna Grand Caravan
I can't work out why this may be the case? Could this be something to do with the altitude making the GPS sensor ineffective? Or maybe to do with being inside an aircraft? The location tracking works absolutely fine at ground level such as when tracking a route in a car.
I am collecting location updates the same way as in the Android documentation, available here:
https://developer.android.com/training/location/request-updates
Any help would be greatly appreciated

Google FusedProvider does not call onLocationChanged() in an environment without GPS

My app works fine if the area has GPS (such as outside) or in houses/first or second floor buildings but it does not receive a location update if the area is something like the 4th-10th floor of a tall building, is this expected behavior or is this a limitation of location services?
Even with an internet connection on a high floor it still does not receive an update, this makes me believe that it is not falling back to Wi-Fi/mobile networks but I tried setting my Location method to Wi-Fi/Mobile only in the Android settings but it still works in normal environments.
Can anyone give me advice on what is happening? Do location services simply not work at higher altitudes or certain areas with very poor reception? I have not tested it in underground parking areas though.
I am using PRIORITY_HIGH_ACCURACY as my priority.
I am using PRIORITY_HIGH_ACCURACY as my priority.
That's the reason you are not getting Location change inside a building. Because HIGH_ACCURACY gets location from GPS provider. As we know GPS doesn't work well inside houses as it collects location from satellite.
You can try out other options.
PRIORITY_BALANCED_POWER_ACCURACY (About 100 meter)
PRIORITY_LOW_POWER (About 10km)
PRIORITY_NO_POWER (Act as a passive listener )
You may visit here if you havn't yet. Hope this helps.

FusedLocationProviderApi, PRIORITY_BALANCED_POWER_ACCURACY and GPS usage

I'm creating an app which tracks the location through FusedLocationProviderApi in a Foreground Service.
When I create LocationRequest with PRIORITY_BALANCED_POWER_ACCURACY and start listening for location updates, to my surprise GPS fires up ( Location in the phone settings is set to High Accuracy). I get the location almost immediately (through wifi/cell sources I guess), but as I'm indoors I can't get a GPS fix and it just keeps on trying without end...
Even though I didn't ask for PRIORITY_HIGH_ACCURACY I get hit with significant battery drain and get blamed for using GPS for several minutes.
Is there a way to set a timeout for GPS search (detect indoors situation)?
Is it possible to get a decent location using FusedLocationProviderApi without automatically triggering GPS or do I have to revert to the old location API?
Do I have to resort to limiting each LocationRequest to couple of minutes (setExpirationDuration) and create a new one to prevent the GPS battery drain?
[EDIT]: I think I might have found an another culprit. On a map tab in the app I have set setMyLocationEnabled(true), and this seems to be causing the GPS to flare up. I will experiment a bit more and post the results. Still I'm interested in how the location manager decides that enough is enough when it comes to GPS fix attempt.
Thanks in advance!

Getting GPS co-ordinates quicker programmatically without internet, but using network provider and mobile GPS

I have referred many questions on this topic, but it seems some of my requirements are missing:
I want to get the GPS location at ~0.0001 accuracy
Don't want to use internet; Though GSM/CDMA network is ok
Should be obtained programmatically when the app starts
Should be quicker, say within a minute (like iPhone, which probably works in Airplane mode as well!)
The code should work in most of the devices
The phone may switch-on/off anytime and travel any distance
Is there any way to get just the co-ordinates with above mentioned requirements? Any sample code snippet will be much appreciated.
Checking various apps like "Locate Me", "Maverick", which claim to show offline locations. But in various scenarios without internet, they don't give track the location (in India).
I have referred plenty of old/new questions inside/outside SO. Below are few:
Is it possible to have the gps location while offline with the nexus
7?
Does GPS require
Internet?
How to get current exact location in android without internet
connection?
[Note: I am asking this question on behalf of my Android team and will be happy to clarify the details if asked for. Should you feel that this post belongs to Android.Stackexchange, then kindly move it.]
1. I want to get the GPS location at ~0.0001 accuracy
You can listen only to GPS provider and discard a location when it doesn't have the minimun accuracy you want:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 5, myLocationListener); // "myLocationListener" must be an object from a class that implements LocationListener
// "myLocationListener" implementation of LocationListener.onLocationChanged
public void onLocationChanged(Location location)
{
int MIN_ACCURACY = 5; // in metters
if ((!location.hasAccuracy()) || (location.getAccuracy() > MIN_ACCURACY))
{
// discard this location and keep listening to new location readings
}
else
{
// that's a good reading!
// do somethings you want... blah, blah, blah...
// stop updates when you get the location to preserve users' battery.
locationManager.removeUpdates(myLocationListener);
}
}
2. Don't want to use internet; Though GSM/CDMA network is ok
Yes, GPS works totally off-line. Android can make use of internet ONLY to update A-GPS data cache and provide faster reads in cold-start updates.
3. Should be obtained programmatically when the app starts
Then call item locationManager.requestLocationUpdates on mainActivity's onCreate event.
4. Should be quicker, say within a minute (like iPhone, which probably
works in Airplane mode as well!)
Keep in mind that iPhone works with "high quality hardware". Android can be run on crappy devices. So it'll depend of:
The device's hardware quality;
The number of satellites that are visible in the sky at that moment;
The age of almanac and ephemeris data on gps cache;
GPS can fail to read satellites because user is inside a building or something.
5. The code should work in most of the devices
What is the oldest Android's API you want it to run?
6. The phone may switch-on/off anytime and travel any distance
I didn't get it. What is your concern about this?
------------------------------------------------------------------------------
Update 1:
"...I would like to use Android 4.0 and above..."
I've tested GPS features from Android 2.3 to 5.0 devices. Everything runs pretty fine on all of them.
"...I have observed that 1 geo-coordinates based demo app which was working in other devices, din't work in my LGG3 with Android 5.0. Any idea on that?..."
Did you check GPS permissions on Android settings? (Maybe it's disabled) Or can be a hardware issue? Did you try in another similar device?
"...Suppose the GPS is showing correct location in New York,
I switch off the phone and then switch on after reaching to London,
then will it still show correct location (without internet)?..."
Sounds you're confusing things: reading a GPS location is one thing. Showing that location into a MAP is another different thing!
You don't need to be connected to the internet to do GPS location reading. But, if you want to show that location into a MAP, probably you're gonna need internet (to load map resources, etc.).
If you nedd to stay collecting GPS locations periodically (let's say, from 10 to 10 minutes), then it will be better to use AlarmManager to schedule a timer that will "finger" your app and say "hey, time to make a GPS reading!".
"...Also what is your opinion about the latest Fused API?..."
I've tested it and used it for a while, but I gave it up. It needs that Google Play Services be installed to work (not a problem, most users have it on their devices). But if you need ACCURACY (as I do), it will not work. It uses "fused sensors" (accelerometer, gps, wifi, compass, etc...) to try to get user location with minimum power possibile. Sometimes, it says you're 10 miles away from where you're really is. I couldn't make it work fine to keep the "path" where user has been. But it really saves battery.
Suggestion is to use Google Location Services
It takes the best possible and accurate location as accurate as it can at current moment. It automatically (with configuration of course) takes best current accuracy too - whatever is available GPS, network, internet, GSM/CDMA/LTE... It also cashes last known location so, basically, you know it every moment - the best what you can.
Of course you have to realize that each service provides its own accuracy and in it's own time. Look, for example, GPS Test App on Android and see how accuracy increases with time and used satellites.
Also Location Services is good for you because it simply provides coordinates - just as you asked and hides a lot of work to determine what real service to use based on time and accuracy. However, of course, if none of the services on your particular device and location can give you required accuracy then there is no way to get it. That's why services also provide accuracy measurement.
Here is another link
Use fused location API provided by Android SDK.Implement fused location in a Service and call it in your application MainActivity.

Android Location Updates get stuck

I am developing an android application wherein I need the user location updates pretty frequently. Say 2 times a minute.
Earlier I had been using Google Play Service's "Fused location service" but the location updates were not received as requested.
The location updates got stuck for sometime, the interval between updates jumped to 10min or so.Sometimes even if I put my priority to "PRIORITY_HIGH_ACCURACY" the same happened.
I then went back to the old "Location Manager" and when I used the "NETWORK_PROVIDER", I noticed that the location updates got stuck due to this provider. Also the GPS does not get activated immediately, it takes some time. I am trying to build my custom fused location provider. How can I efficiently switch between providers, without getting lags on location updates.
I want to know what are the best practices for getting location updates regularly, all the time, be it either NW, GPS or both. Like it should work for an application where location updates getting stuck cannot be afforded.
Battery drain is not an issue for me right now.I am aware of all the supporting docs that Google provides regarding location access.
Any help would be much appreciated.
Thankyou !
FusedLocationProvider really is the best option for obtaining locations at the moment, because it uses a lot more than just GPS or Network data to obtain location fixes. I have experienced issues regarding intervals being missed as well, but ultimately this is something down to luck depending on availability of GPS, Network, etc. etc.
My favourite usage of FusedLocationProvider so far is in conjunction with the AlarmManager class: Basically, the idea is to start location tracking at intervals specified by the Alarm Manager (this can be set to every 30 seconds such as in your case). Once the interval is hit, the location provider is to obtain a location fix as soon as possible (so in the setInterval method or whatever it's called, the parameter is a 0). This way, you can avoid having to wait another 30 seconds for a new location, instead having the location tracker attempt to provide a location as soon as possible after the interval specified by the Alarm Manager is hit.
By the way, when making custom location tracking wrappers, be careful of using the .getLastKnownLocation() method as it only uses cached locations - you could end up sending the same location to the user every 30 seconds.
Good luck!

Categories

Resources