android stable location provider - android

I'm not sure which location providers I should use:
20 seconds is the maximum time I can manage without location.
The accuracy is less important for me, I can manage with accuracy of 500m.

Take a look at the location manager class. It will give you the information about location. And because you need an accuracy of 500m , I would suggest you to use gps, as networks(assuming you mean cellular) will have a lesser accuracy.

Related

How to most accurately determine the location of an Android device?

I'm building an app that should be able to report the users exact location. There is only a need for a single location, i.e. I don't need to track the device continuously.
I want the location to be as accurate as possible, and it's okay to wait a short while for the location to be determined (max 1-2 minutes).
I've been looking at FusedLocationProviderClient.getLastLocation(), but since I want the location to be as accurate and updated as possible it doesn't fit my needs.
So I started looking at using FusedLocationProviderClient.requestLocationUpdates() instead, and it seems like a better choice.
But I'm not sure how to best configure my LocationRequest to get as good accuracy as possible. For instance, would it be better to use setNumUpdates() so that I only receive a single update and use that as my location, or should I receive multiple updates in hopes of getting better accuracy (GPS locking to more satellites for example)? I'm thinking that if I use the second approach, I could look at the value of getAccuracy() from each location update and only keep the one with the highest accuracy. The downside is that if the device is moving and I keep receiving updates for a minute or so, the first location could have the highest accuracy, but since it's a minute old it's not accurate any more.
As stated above, I need just a single highly accurate location and it's okay for the app to wait 1-2 minutes for it if needed. What would be the best approach in this kind of scenario?
First, make sure the accurate location is turned on. look at Settings.Secure.LOCATION_MODE_HIGH_ACCURACY It has a noticeable advantage over only using GPS. Then listen for the location for a while and calculate the result you get to find out the best location. You can also detect if the user is moving if the number differs a lot or by using Activity Recognition API. It shouldn't be very hard to write this calculate function to get the best result.
I'm not sure about this but I really don't think waiting more than a few seconds gives you an advantage. to be sure you can simply alter this time and watch the result.
You might want to use LocationManager. In my experience FusedLocation will indeed appear to lock faster but may not be as accurate overall, or at least for a while. I have an app that also requires pretty accurate coordinates. My default is to use a LocationManager based approach but users can switch to a FusedLocation provider if they want faster locking (like when indoors).
This is a good overview https://developer.android.com/guide/topics/location/strategies
For the provider when requesting updates I'd use LocationManager.GPS_PROVIDER. It will take longer to lock since it will wait for satellites and not use Wifi or other towers. But you said that's OK. Something along these lines
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, YourLocationListener);
Once you start getting location updates via your listener's onLocationChanged() you can start to inspect the location for accuracy, movement from last location change, etc. to try and evaluate if the GPS receiver is still settling in on a location. Once you are satisfied with the quality of the fix you can stop receiving location updates (locationManager.removeUpdates(YourLocationListener)) and then run your logic that needs the location. The link I provided has good info about this too.

How to get accurate position from GPS periodically

In application I need to get geo position of phone every x minutes (for now it's 5min and 50m), in such a way that phone doesn't discharge during day. The accuracy of position must be at least 40m. By now I have listeners for gps and network. The problem lies in the fact that the data I can receive sometimes is totally wrong (depends on phone) - new position can be even 200m from my real position and with 40m accuracy; next point can be the same but in opposite direction. For my app it's fatally.
So the question is next: Is there any way to get more accuracy data but not very often?
Update 1: to show the problem in action:
(The phone is lying in the fixed position)
To get more accurate location make sure you're using the ACCESS_FINE_LOCATION permission in your manifest. To prevent higher battery usage, you can use setInterval and setFastestInterval on your LocationRequest object. Longer intervals mean less battery usage by your app.
You should not be accessing the gps and network directly, you should be using LocationManager and using ACCURACY_FINE in your Criteria. This will help conserve battery life, and avoid issues with phones where the gps may have been disabled. There's more detail on that here.
As far as the accuracy of your location, you can use Location's getAccuracy method to get Android's estimate of how accurate a measurement is. If it doesn't fit your criteria, discard it and poll again.

What is the difference to getting the location by using Location Manager and Fused Location Provider Api?

I need the real time difference to getting location using by Location Manager and Fused Api. I have checked with both, in Fused api(GPS) I am getting 7 digit after decimal point, but using by Location Manager(GPS) I will get nearly 15 digits after decimal point.
Which one is better to get accurate user current location?
What is the difference between Location Manager and Fused Api?
Why we need to migrate from Location Manager to Fused Api?
I used LocationRequest.PRIORITY_HIGH_ACCURACY, suppose I am in indoor, network is not available, how it returns the location?
Is it return the lastknown location, even I didn't write the code in onConnected()?
Related
Have found a previous answer for you, looks like FusedLocationProvider is going to be better
I think that the difference between them is that one use the physical sensor directly (Location Manager), where as other take assistance from the network/internet .
To me the more accurate is Location Manager but it takes some time and location detection speed depends on some factors such as you are on open place or not , weather etc..
I think the difference is:
Location Manager: you can choose specific resource provider such as
LocationManager.GPS_PROVIDER or LocationManager.NETWORK_PROVIDER
FusedLocation supplies a fast way to detect your location using combine of these provider above.

Obfuscate location to show a given level of accuracy

Let's say that I want to get the lastLocation but with an accuracy no better than 1km, how can I do that? Does Android provide an easy way to do this?
I know that COARSE_LOCATION obfuscate it to a block level, but that isn't enough.
Why I need this? There is a law that requires that in some cases the app shouldnt return an accurate location.
Let's say that I want to get the lastLocation but with an accuracy no better than 1km, how can I do that?
You don't. You get a location. It will have whatever accuracy it has, which you can determine via getAccuracy() on the Location object. Other than by choosing coarse versus fine, you do not have control over the actual accuracy.

How to get accuracy of GPS in Android

I need to check the accuracy of GPS... but when i use location.getAccuracy then it doesn not return me any value... Does it take time..If it takes time then how long does it takes?
In android devices, mainly you can have two sources by which you can get position info : GPS_PROVIDER and NETWORK_PROVIDER
GPS_PROVIDER uses your GPS chipset to get a position fix. This has a greater accuracy.
NETWORK_PROVIDER uses the information from cell-tower to triangulate your location. Hence its accuracy is not as quite good.
You can get your accuracy info from Location.getAccuracy() or from NMEA data.
Does it take time..If it takes time then how long does it takes
Once you've started getting fixes it won't take much time. Time to first fix can be 30 seconds to 15 minutes. It depends on your GPS chipset, terrain conditions, cold/warm start etc.
To choose the best provider read this article

Categories

Resources