Network provider stops providing updates - android

I have noticed that rarely (every few days), my app stops receiving new location updates.
The location listener is registered with both network and GPS providers. The GPS provider is off so any location updates come from the network provider. Every few days or so, I notice the location is old and not updating. From my debug log I can see that the location listener is being registered with location manager but there are just no new locations being found. onLocationChanged() is not called.
The strange thing is, Google Maps has no problem getting a new network location. Restarting/reinstalling/clearing data on the app does not solve the issue. The only thing that solves it is to restart the phone.
This has happened on 3 different devices (2 ICS, 1 JB).
Similar problem but not worded very well here.

Related

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!

Can't get any location on Android device, while Google Maps can

I am writing an app which needs to get any fresh location. Accuracy does not metter. My app will mainly be used in buildings, so I am using Network location provider as a main location source.
I have troubles on some devices as follows:
My code can't access any location. But when I start Google Maps on the same device - it shows correct location. I switch back to my program and it does not see any location again.
My code does roughly the following:
Check if Network location provider is available with code below:
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
If network provider is enabled - requirest single location update:
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Code also starts Timer for 5 seconds. If code does not get requested location update during 5 seconds, then timer is iterating throuhg all available providers trying to get last known location and pick up the best one:
Location location = locationManager.getLastKnownLocation(provider);
The result of all these moves is that network provider is On, but code does not get any updates. Timer starts, loops through all providers and all of them does not have any last known location. getLastKnownLocation method returns null for all of them. The most strage thing is that Google Maps got correct location just a few seconds before this. I've rebooted device with no effect.
I examined best practices of getting location here. They seem to use the same approch as I currently do. Are there any tricks I am missing?
This problem occur in some devices the solution is try to get location from GPS if fails then get location from WIFI device

GPS is not working inside the building

After few hours of testing outside of house, when i came back to my house i found that GPS is enabled but was not getting location fixes inside the building.Hence its onLocationChanged method couldn't get called.
Problem: How to know that GPS is not getting any location fixes as device continue to sense your location in "trying mode".By trying mode i mean the situation where it is not coming to any result even after 20 to 30 minutes still it declared it self as enabled (blinking in status bar).
How one could know that the GPS doesn't get location so switch to another provider like Network_Provider.
In short i want to get my device to conclude something that GPS can find location fix for sure or you have to take location by another means.
I hope at least someone can give me idea about how to deal with that.
The link below has an awesome tutorial, of how to get the location from GPS and/or Network.
It uses a timer task, which analyzes if there is a GPS location in a specific period of time, assume 20 seconds. If not, it will return the location from Network as the current location. If there is a location from GPS, then it will compare which update is new (latest), and return that.
What is the simplest and most robust way to get the user's current location on Android?

Requesting location updates while Google Maps Navigation is actively running

I would like to request location updates from LocationManager using the GPS provider only. I understand that doing this does not immediately return location results.
However, let's assume that the user is currently running the Google Maps Navigation app (i.e., there is an active route) and their GPS signal is strong. Would requesting the GPS location yield a result quickly due to the fact that it is constantly being fixed? Or am I making an invalid assumption?
Furthermore, if I were to call getLastKnownLocation(LocationProvider) while the Navigation app is running, can I assume the last known location will be very close to the current location? How often is the last known location updated when the Navigation app is actively navigating?
Thanks so much!
Would requesting the GPS location yield a result quickly due to the fact that it is constantly being fixed? Or am I making an invalid assumption?
Furthermore, if I were to call getLastKnownLocation(LocationProvider) while the Navigation app is running, can I assume the last known location will be very close to the current location?
If you have a Service that listens for GPS updates, you will have access to the most recent data returned for any application. I recommend using the PASSIVE_PROVIDER which will receive updates from any provider as they arrive.
I get the GPS fix in my HTC Incredible within 30 secs, regarding your question I tried opening the Navigation app and my application, I dont see any difference if I am running just my application alone.
Would requesting the GPS location yield a result quickly due to the fact that it is constantly being fixed?
The GPS yield a quick fix that depends based on the Satellites.

When does the network provider update the location in android

I use network provider to get location in Android application. Sometimes I found the location would not be changed even after I arrived at a new place. At the same time, I found the locations were changed in Google Map. So I quit and restarted my application, and the locations wasn't changed either. But after a long period, or I reboot the phone, I could see the new location.
Does any one know what's the reason ? I have used getLastKnownLocation() to get the latest location in my application.
Update:
When this problem happened, I found the cellid and LAC was changed while the location wasn't changed. So it's very strange. I think Google Map may use cellid & LAC to get the location directly, so it can get the correct location.
More update:
When this problem happened, I used the cellid and LAC to get the location via HTTP POST request from Google server. This location was correct.
BTW, I found my question was like this question: Android network location takes hours to update location
I wouldn't trust getLastKnownLocation(). In my experience this isn't reliable.
You'd be better off requesting location callbacks using LocationManager.requestLocationUpdates(). If you only need the location once you can then unregister for the callbacks using LocationManager.removeUpdates() after that. If your application needs to be notified when the location changes then you can register for callbacks with a reasonable minium-time and/or minimum-distance parameter (based on whatever your application requires.

Categories

Resources