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.
Related
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.
I've been working on an app that needs to be location-aware, and I've noticed that there are two (or more) methods of receiving location: with Google Play services (as seen here developer.android.com/training/location/retrieve-current.html#GetLocation) and with Location Manager, Providers etc. (as seen here http://www.vogella.com/tutorials/AndroidLocationAPI/article.html#locationapi_criteria).
What is the difference between these methods (if there is any)? Which one is more accurate?
edit: ok, I see that I sent the wrong link on the first thing. Won't this code (http://developer.android.com/training/location/receive-location-updates.html) give me location updates? Generally, what's the most accurate way to get my location?
The one with the GPS is accurate and that which is based on Network is not. Google Play Service use FUSE api to get the GPS location first, if the location is found (that's great), otherwise it will try to get location fix from Network Tower. In Short the one with GPS is accurate
The first method provides the details of LastKnownLocation. ie. the last location received from GPS or network provider when you or other apps accessed the location services. After that there are chances you moved a lot and it need not be your current location. So if You are planning to create an application that requires accurate location tracing, You should fetch the location as in the "Vogella" method. If the current location is unavailable, you can try using the last known location (As a plan B :-)).
I'm writing an application which requires that an accurate GPS location is taken at the moment a particular action is taken - specifically, by law we have to prove that we were at someone's house when we said we were.
I have already implemented a Location Listener to update the location for live-tracking purposes, but I also require an on-demand update from the device's GPS.
Using GetLastKnownLocation does not appear to force the GPS device to update - instead, I am getting the last location received from the onLocationChanged event.
Is there a way to force a device to update and get the current location, instead of either getting the last known location or waiting for another onLocationChanged event to fire?
Try using Thread that runs at a particular interval of time and gets the location data..
So that you can use it later..
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?
I am building an app that can use a user's current location on certain actions. Location is more of a benefit to the user rather than a critical part of the process. I'm only interested in very rough accuracy and it can be off by 5 or even 10 miles and still be of value. General plan was to see if the network provider was enabled and then just do
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
Assuming that no other apps are running, will the phone automatically periodically update the network location? I.e. there will likely always be a value returned by this code which will meet my needs?
EDIT:
I've been doing a bit more research and I think the question I was really trying to ask here was if the Android operating system or the phone itself would update the last known location for the network provider as the phone locked onto different cell phone towers or wifi networks. The answer appears to be no. After force stopping all apps on my phone which I know to interaction with location services, the last known location has stopped updating. So, I'm guessing that these days chances are that most phones will have some location services running in the background updating the last known location but the phone itself won't do it. Hence I think I'll be going with some form of requesting location updates if the last known location is too old.
getLastKnownLocation() only returns the last fix. So if no location providers are being updated the return value of getLastKnownLocation() will not change. The location object will also provide you with accuracy and time of the fix.
I would look at this post for more information. You could use some version of the one shot location.
http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html
Frohnzie is correct about getLastKnownLocation. Getting location is an expensive operation, so it only happens when an app requests it. I've often driven 30 miles or so, opened the foursquare app on my phone, and it showed me venus that were 30 miles away. Clearly they were using getLastKnownLocation.
For your use case, I would recommend LocationManager.requestLocationUpdates. You can specify an accuracy and a timeout. So if the phone can't quickly find a rough estimate of the user's location, you can just forego location since it is not crucial to your application.