I have an application that uses a Network provider for its location. Every time the apps starts it checks to see whether the Network provider is enabled using isProviderEnabled() method in LocationManager.
If it returns false I present an alert to the user to enable Network Provider and then use the application. This logic had been working really well, with a few exceptions with non-Google certified devices(not a concern since they usually do not have Maps API either). Lately, with some devices on ICS and now on JellyBean emulator, I get a consistent "false" for isProviderEnabled() even though it is enabled.
I have since moved to use the string returned from
Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED)) to see whether it contains "network". It is a hack but it is working for now. I would love to be able to use isProviderEnabled() method.
Has anyone seen this issue before?
#naqi #gkris
I also noticed this issue where isProviderEnabled(LocationManager.GPS_PROVIDER) was returning false.
Solution to this is to also ask user to set the Location Method to High Accuracy instead of Battery Saving or Device Only
This setting is available under location settings and has different name on different devices. On some devices that I have tested on, this setting is with name Mode, Location Mode, Location Method etc Also the value can be High Accuracy or GPS or GPS, Wifi and Mobile Networks
Developers will have to train users on this.
From the API doc for : LocationManager.GPS_PROVIDER
This provider determines location using satellites. Depending on
conditions, this provider may take a while to return a location fix.
Requires the permission ACCESS_FINE_LOCATION.
So if you're not requiring ACCESS_FINE_LOCATION it will return false.
Related
We use in Cordova with plugin "cordova-plugin-locationservices"
Sometimes we get location that a few km away from real location.
we call to "getCurrentPosition" with next options:
{
timeout: 60000,
enableHighAccuracy: true,
maximumAge: 0,
}
Someone use in this plugin and use in another options or recommend on another plugin.
At first we use "cordova-plugin-geolocation" with same options but it's also sometimes return not accurate position.
I've written extensively on this topic at https://breautek.com/articles/geolocation-accuracy.html
But to summarise there are a number of reasons why you aren't receiving the accuracy that you're after.
The two main contributors to inaccurate readings are 1) Settings & 2) The environment.
Natively, the GPS service operates in two modes: Fine location and coarse location. Fine location will allow you to get approximately up to 3-5 meter accuracy and is generally used if you require information such as the specific street. Coarse location gives you a very low accuracy reading that can only be useful to determine the location of the user's state or country.
Settings includes both programmatic settings, such as the enableHighAccuracy parameter, and they include User device settings, which is configurable by the user on based on their own location preferences.
The developer obviously has control over programmatic settings, and it looks like you're doing just that. However, the developer doesn't have access to change user preferences of the device. Just because the user has consented permission for your app to use location, doesn't mean they have location services actually enabled, or even configured to provide fine location. The specific settings can vary from device to device or by OS version to OS version. But generally speaking they usually have some sort of "Device/GPS only", and "High Accuracy" (sometimes labelled as "Bluetooth/Wifi/Mobile") setting for geolocation. It's the app's responsibility to handle these situations.
In my apps, I use the mixture of the cordova-plugin-geolocation as well as the third-party diagnostics plugin. With the diagnostics plugin, you can check if permission is granted, including for fine/precise location, as well if location services are indeed enabled.
Lastly, the second issue could be the environment. Even if the device is configured and the app has permission to use fine location, you still may not actually receive accurate readings. This can be caused purely based on the environment. Being located in a concrete office building for example hinders a lot of GPS capabilities.
It's recommended to pay attention to the accuracy field in your GPS callbacks, which will tell how confident the GPS service is that the given GPS point is accurate. The accuracy reading is in meters which tells you that the true location is within X meters radius of the given location. So in otherwords, the lower the number the better.
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.
I have code that successfully gets location updates from multiple providers and filters them to give a current best estimate.
I added code to check for the returned Location.hasSpeed() and .hasBearing() values to do some bearing related calculations when the user is actually moving.
It all works fine on a Huawei Sonic running 2.3.3, but on the Google Nexus S running 4.0.4 the GPS provider's Location always returns false for .hasSpeed() and 0 for .getSpeed().
When I register my location listener, the GPS provider returns true for .supportsSpeed() but it never returns the speed in a Location even when the accuracy is down to 30m and it is physically moving (in a car, on the dashboard for max reception, screen on).
Is there some difference from 2.3.x to ICS 4.x?
Do I have to implement my own speed calculation even when the provider reports support?
Google Nexus S has history of problems with GPS. I don't think that it's specifically related to ICS. Have you tried Factory data reset the phone and then retry it?
I'm trying to figure out the location services options under Android 2.3.3 on my Verizon Droid X, I have 3 options:
Google location services
Standalone GPS services
VZW location services
Enabling or disabling Google location services causes the following to return true or false respectivly.
myLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
Enabling or disabling Standalone GPS services causes the following to return true or false respectivly.
myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
Enabling or disabling VZW location services seems to have no affect on the isProviderEnabled method. If this option is the only one enabled, then the isProviderEnabled method always returns false regardless if using NETWORK_PROVIDER or GPS_PROVIDER.
The way I understand this is:
Google location services = WiFi MACID location
Standalone GPS services = GPS location
VZW location services = nothing except something special to Verizon (like Navigator)
Is this assumption correct? If so, where does AGPS and CellID come into play?
"Each kind of location service is being used not only to help their applications bring you the most relavent information, but to assist the network in improvements based on your individual experience.
Google wants to know where you are to answer your questions of 'Coffee shops near my location' and various other things.
Verizon uses your path from tower to tower to tower as you travel to make someone else's (or your) trips through the same area more efficient. If while driving up a highway you are on tower A and tower B, C, and D are all coming in to range, but your phone always goes for C...in the future, tower A can just tell your phone to look for tower C rather than have it search blindly.
There's a lot more detail behind the scenes, but that's the general idea."
see reference link below for more details
http://www.droidforums.net/forum/motorola-droid-x2/159360-location-security-settings-questions.html
Before I go into location based mode I check for existence of any location providers by calling
List<String> android.location.LocationManager.getProviders(boolean enabledOnly) //enabledOnly = true
and checking the size of the resulting list.
Now I tested my App on a HTC Desire with Android 2.2. The system settings don't allow any location tracking (GPS and mobile is turned off).
However, the list get returned has 1 entry, whose value is "passive". What is it? Can I work with it? The provider seems to be slow / not working.
From the Android API reference:
A special location provider for receiving locations without actually initiating a location fix. This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will return locations generated by other providers.
So no, it's not likely to do you any good if there are no other location providers available.