Android location accuracy - android

I have the following code implemented to retrieve location values on Android:
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
On Android 2.3 and 4.1 this works great and returns updates at 180 samples per hour with a resolution down to 100m or less.
However, on Android 4.3 something has changed so this only provides updates at 5 samples per hour and a resolution at 2km. I haven't tested on later versions.
What has changed? Is it possible to return to the old accuracy levels again? I don't want to force GPS for power reasons. The app has ACCESS_COARSE_LOCATION permissions.
I have been testing this on a Samsung S3 if it makes a difference.

Use Google's LocationServices API instead:
https://developer.android.com/training/location/receive-location-updates.html

LocationManager.NETWORK_PROVIDER do not provide accurate location it provides you the location according to the cell tower you connected,sometimes it provides location with accuracy of 100m sometimes with 2-3km,if you do not want to get the location from gps due to power reasons i would suggest you to use fused location provides as this is an efficient and effective way to get the location on android and Google also recommends this,you can read more here in this example http://www.kpbird.com/2013/06/fused-location-provider-example.html

Related

Is Fused Location Provider good choice?

I am developing an application where I want to use Fused Location Provider. But I have some doubts, and couple of questions.
When GPS is off and I set priority to HIGH, does that mean that the GPS will be automatically turned on, or not?
Can I set UpdateLocation with Fused provider with HIGH priority on demand to save battery at least a little bit?
How can I know what Fused provider is using (is it a GPS or a network provider)?
And finally
Is Fused provider really the best choice for android location? Are there any negative points about it?
What is your opinion?
Thanks in advance.
When GPS is off and I set priority to HIGH, does that mean that GPS will be automatically turned on, or not?
No, it will not be turned on automatically. But if you use SettingsApi, will prompt a dialog to user and gives information that GPS is must be turned on. If user accepts it, the gps will be active automatically. Check the SettingsApi
How can I know what Fused provider is using (is it a GPS or a network provider)
If you use fused provider api with SettingsApi properly. It will make adequate the required settings for current location request.
Is Fused provider really the best choice for android location? Are there any negative points about it?
In my opinion, before fused provider you must deal with directly providers(Gps, network) But fused just asks you, "how accurate locations you wanna receive ?"
As in here https://developer.android.com/training/location/index.html stated very clearly that, the Google Play services location APIs are preferred over the Android framework location APIs (android.location) as a way of adding location awareness to your app. If you are currently using the Android framework location APIs, you are strongly encouraged to switch to the Google Play services location APIs as soon as possible. So I hope you got your answer.
I made a testing application for Gps, Wifi and Fused Location Provider and testing it for 2 days. It's better because it uses both of them and most of the time it's the one most accurate. Also, Gps data is a very noisy data that causes jittering, to solve this low-pass filter or other filters are used. One of the most successful filter used to get most accurate results is Kalman Filter. FusedLocationProvider use this filter same as RotationVector which is a fused sensor combines hardware and software. RotationVector uses accelerometer, gyroscope(if available), and magnetic field sensor to get and filter positition and azimuth data.
Location.getProvider for Gps with LocationManager returns "gps", Wifi returns "network", and FusedLocationProvider returns "fused".
When GPS is off and I set priority to HIGH, does that mean that the GPS will be automatically turned on, or not
Anything other than "Battery Saving" turns Gps on if available. This settings available on my Android 7.1.1 phone. Setting for location was different on previous versions of Android on user's side. As a developer to enable using Gps you should set mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
PRIORITY_HIGH_ACCURACY - Use this setting to request the most precise location possible. With this setting, the location services are more likely to use GPS to determine the location.
Setting Priority also determines battery use level too.
Can I set UpdateLocation with Fused provider with HIGH priority on demand to save battery at least a little bit?
Yes, you can set interval of location request in addition to priority.
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
How can I know what Fused provider is using (is it a GPS or a network provider)?
Location from Wifi never returns true for Location.hasSpeed() but Gps returns almost always true if you are outdoors. Also location.getExtras() have satellites tag which you can check for satellites which is only available for Gps. Speed may not be correct if you are walking or as far i've read so far, i haven't tried this on car, when speed it less than 5km/h it's not very accurate. I mean if you are using FLP and last location data contains speed info it's definitely from Gps.
Are there any negative points about it?
As of Android 8.0 and above there is location retrieving limit if you do not use a Foreground Service or get location on foreground while app is not paused for both FLP and LocationManager.
Also FLP requires GooglePlayService to be available on user's device and it should be above a particular version. 10 or 11 depending on which one you use. This can be trouble if you wish to publish your apps on a country, for example China, that bans Google Play Services.
The existing answers don't say why the FusedLocationProvider is better.
It is better because the API fuses from more data sources (sensors, wifi, context, history) in an intelligent and battery-saving way. Also, Google is always improving it by adding more data sources. If your app uses it, you get those improvements for free.

How does the fusedLocation API interval relate to turning off the GPS radio

Let's assume I'm used the Android fused location API to request highly accuracy location reporting. For example,
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(FASTEST_UPDATE_INTERVAL*2);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi
.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this)
This results in my location listener getting called up to every FASTEST_UPDATE_INTERVAL. If I set FASTEST_UPDATE_INTERVAL to be short I know that the GPS radio will not be turned off between location updates. I know this from various sources such as Fused Location Provider unexpected behavior and https://www.quora.com/Why-does-GPS-use-so-much-more-battery-than-any-other-antenna-or-sensor-in-a-smartphone.
My question is what is the smallest value of FASTEST_UPDATE_INTERVAL that will result in the GPS radio being turned off between location updates?
I anticipate there will not be a clear answer to this question, and that it will depend on the phone hardware, the Google Play version and probably other hardware and software factors. Nonetheless a general answer would be helpful.
This question is important because I am interested in using high accuracy locating but minimizing battery use. To a point I am happy to increase FASTEST_UPDATE_INTERVAL if it will save power.
Wouldn't it be nice if the google fused location services used the device's motion detectors (if they exist) to work out when it was stationary and if so simply turned off the GPS radio until the device moved.
Even if you found an answer, I wouldn't count on it remaining the same between devices, OS versions, or Google Play versions. If you absolutely don't want GPS, don't used the fused provider. Use the network provider from the base LocationManager.
As for using motion detectors- they don't exist. It has an accelerometer, but to an accelerometer staying still and traveling at a constant 50mph look exactly the same (traveling at constant speed is 0 acceleration). It might not be a good optimization anyway- getting a lock on multiple GPS satellites takes several seconds. You don't want to keep turning that on and off if someone wants accuracy.

Android gps location real accuracy is bad

I get location in LocationListener configured with following code:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 5.0, locationListener);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 5.0, locationListener);
Locations which I get are innacurate very often. Accuracy in location for "gps" provider is about 10-20 m, but in real it can be about 500 m. And in native Android application Google Maps I see my location accurate enough.
I have suspicion that Google use some another API. Is there present another way to get locations in Android?
OS: Android 4.4
Smartphone model: Doogee Voyager 2 DG310
Google apps use a proprietary provider called "Fused Location Provider" (read more here). This provider still uses the network and GPS providers present in the background.
The first location fix from network provider will most of the time be grater than 1000 m in accuracy because it comes from a BTC (cell tower). After a few seconds it should drop to around 20-50 m accuracy based on Wi-Fi. The GPS provides locations usually with max accuracy 20 m but this can increase when you're in a densely populated area with tall buildings and bad connection to GPS satellites.
I recently discovered the Smart Location Library which should provide easy access to either GPS, network or fused providers in combination with Activity Recognition to decrease battery drain.

GPS works better with google maps than my App android

I have an app in android using GoogleMaps API.
When i use google maps, I active gps and it find me so fast.
When i use my app, it takes some seconds, and if I'm in my house, gps dont find me. WHY ?
A short summary of my code:
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
MyLocationListener = new MyLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
7000,
5,
MyLocationListener
);
Thx for answers and sorry for my poor english
EDIT
Thx for answers ! the problem is that i dont want to use network provider. Wifi is exelent, and 3g have a 400 meters error jejeej.
I only want to know, why google maps, using GPS, find me in 1 second with perfect position Although I stay in a house.
Your answer is "use coarse locate". If google maps use network providers befor gps, its impossible he find me so fast. :(
GPS is using satelites, When you are indoor it can't get the signal from the satelites hence it can't find location (can't get a fix).
The GPS needs signals from at least 4 satelites to get a proper fix, that usually takes a few seconds, once you already have a fix you can maintaine it very easly. therfore if you are using google maps it will get you a fix faster.
To get a better understand on how GPS works, check this link
You might want to use different location approachs for getting location indoor (coarse location could be the answer). I would also consider using the fused location by Google play services, it gives you a wrap up on the location providers and get you location based on what avilable at the time (meaning GPS, coarse - wifi or network).
You should try using Coarse locates for a quick locate followed by a fine locate to have a more accurate location. The coarse locate is usually very fast, while the fine one takes more time.
Basically, the idea is to do multiple locates and overriding the less accurate ones by the newer and more accurate locates.
You can find more info on the Android dev doc: http://developer.android.com/guide/topics/location/strategies.html
EDIT: if Google Maps is able to find you so fast, it is because you are not moving and they use the knowledge of the last location. Please read the above link that gives a lot of useful information for Location strategies (and it works very well).

Android GPS accuracy

I'd like to use fine gps position in my app. So I followed a simple tutorial (basic usage of LocationManager, explicitly reguested GPS provider, ask for updates 0 ms, 0 m ) and create an app. I was totally not impressed with accuracy and speed of updates. It was slow and best accuracy was 24 meters, but on average 96.
On the same phone, from the same location I run widely known GPS STATUS. And I was amazed to see how accurate the fix was. 4-6 meters, consistently.
So I switched off GPS Status and run my app - I see accuracy 6 meters, but seconds later it is 24, 56, 90, 128.... And fluctuate around 96.
Now, I wonder: how this is possible? Are there tricks to boost accuracy?!!
Does anybody have good examples/tutorials?
it does not help
Let me repeat: I get and print ALL updates. So I see a stream of locations with accuracy.
I see fluctuations, I see best results, and it is never better then 12 meters.
Now in the same spot, I start GPS Status => and I see how accuracy goes to 4 meters!
First I thought: ha, GPS STatus cheats, just devides the accuracy
But it seems to be not the case, because when I switched my app on and get lastknown positon it is indeed the one with accuracy 4!
And start to degrade to the best case 12.
Summary: same hw, same conditions, different apps => different accuracy!
So my question: are there any tricks? Any extra commands? Any special power settings? Any relations to "how heavy you app"?
related to: Android GPS. Location Listener does not want to acquire a fix :(
The best accuracy you can get with GnssMeasurement, but is hard to code. Android 7+ I have Doodgee shoot dual(very not popular china smartphone) and work's. https://developer.android.com/reference/android/location/GnssMeasurement
https://developer.android.com/guide/topics/sensors/gnss (official support list).
GNNS(GPS/GLONASS/GALILEO/...)
LocationManager,( 0 ms, 0 m ) - don't work, after some times(1-20s) you will get this same coordination(if you will stay in one place)- accuracy is 3-10m. With LocationManager you dont get the "raw" GNNS data from physical modul, but calculated by Android API. With GnssMeasurement you can got it.
google has released a nice API on their recent Google IO 2013 event:
https://developers.google.com/events/io/sessions/324498944
you should check it out and see how you can minimize your code.
do note that it requires that the device would have the play store app for this to work.
this method has many advantages over using the normal location sensors (battery, speed , accuracy,...)
How about this?
-set accuracy + set power requirement high:
try{
locator = new GeoLocator(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.addGpsStatusListener(new GPSStatusManager(locationManager));
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria. POWER_HIGH);
bestProvider = locationManager.getBestProvider(criteria, true);
Bundle bundle = new Bundle();
//I copied the next two lines out of some tutorial hoping that they would help boost my gps, but I'm really not sure what they do
boolean xtraInjection=locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER,
"force_xtra_injection",bundle);
boolean timeInjection=locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER,
"force_time_injection",bundle);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0.0f, locator);
}catch(Exception e){}

Categories

Resources