Get *coarse* location from GPS provider on Android - android

My app only needs very rough location data, so I originally set my manifest permissions to ACCESS_COARSE_LOCATION, and set up a location listener for NETWORK_PROVIDER. This gave me exactly the kind of rough location estimate I needed, but only with Google Location Services turned on.
I was expecting that if the user only had GPS enabled, that I would still receive a rough estimate of their location. But it seems like the only way to get ANY location information from the GPS_PROVIDER is by using the ACCESS_FINE_LOCATION permission.
So, is it true that with only GPS enabled, an app cannot receive location information unless it has the ACCESS_FINE_LOCATION permission? In other words, the GPS_PROVIDER can't send rough location estimates if the app only has ACCESS_COARSE_LOCATION permission?

So, is it true that with only GPS enabled, an app cannot receive location information unless it has the ACCESS_FINE_LOCATION permission?
Generally speaking, yes.
Quoting the documentation for LocationManager:
If your application only has the coarse permission then it will not have access to the GPS or passive location providers. Other providers will still return location results, but the update rate will be throttled and the exact location will be obfuscated to a coarse level of accuracy.
In other words, the GPS_PROVIDER can't send rough location estimates if the app only has ACCESS_COARSE_LOCATION permission?
Quoting the Android 4.2 release notes:
Compared to previous versions of Android, user location results may be less accurate if your app requests the ACCESS_COARSE_LOCATION permission but does not request the ACCESS_FINE_LOCATION permission.
To meet the privacy expectations of users when your app requests permission for coarse location (and not fine location), the system will not provide a user location estimate that’s more accurate than a city block.
However, I am assuming that this does not supersede the "will not have access to the GPS" statement from LocationManager. I assume that this means that NETWORK_PROVIDER data might be inhibited, if it is deemed too accurate.

Related

Getting device location Android

I'm new to android but my current project requires to work with gps tracking. I've searched the web to find some answers, and some topics confused me. Can you tell me please, I'm not sure I've understand:
Where do we need to use coarse and when fine?
whats the main difference between using NETWORK_PROVIDER and GPS_PROVIDER?
From the documentation:
If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. Permission for ACCESS_COARSE_LOCATION allows access only to NETWORK_PROVIDER.
So in short, the difference is the level of details of the location you get.
The network provider determines the location of the users using cell towers, wifi access points etc. Distance between towers and user’s position are considered in the case of cell towers. This location provider offers a faster response but can be fuzzy.
The GPS provider determines the location of the users using satellites. This is usually more precise, but takes more time.
Note: there is also a PASSIVE_PROVIDER, which doesn't actively requests location, but is able to eavesdrop on other app's requests, i.e. it gets location information when other apps ask for it.
Fused Location Provider gives the location technology and gives you the best location.This api gives the user access to the best location without using much power on the device.
Add to your manifest
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
In activity code
private FusedLocationProviderClient flpClient;
flpClient = LocationServices.getFusedLocationProviderClient(this);
to get the last known location
flpClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
#Override
public void onSuccess(Location location) {
if (location != null) {
// Logic to handle location object
}
}
});
Look at the api for further explanation https://developer.android.com/training/location/

Android detects only mock locations?

I am making an app in which I want to get the users' location to show on a map. When I am running the app on a real device, it does not seem to get this location, but it gets locations if I put in mock locations using a GPS location faker. In the emulator these mock locations are also detected.
How can I get my phone to get the real location too?
Requesting User Permissions In order to receive location updates from
NETWORK_PROVIDER or GPS_PROVIDER, you must request the user's
permission by declaring either the ACCESS_COARSE_LOCATION or
ACCESS_FINE_LOCATION permission, respectively, in your Android
manifest file. Without these permissions, your application will fail
at runtime when requesting location updates.
If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need
to request only the ACCESS_FINE_LOCATION permission, because it
includes permission for both providers. Permission for
ACCESS_COARSE_LOCATION allows access only to NETWORK_PROVIDER.
Read more at https://developer.android.com/guide/topics/location/strategies.html#Permission

why ACCESS_COARSE_LOCATION needs to location must be enabled

I am trying to get user location with low battery consumption and without GPS (location). Milimetric coordinates are not necessary for me. So I decided to use
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
and also at this google developer docs https://developer.android.com/guide/topics/location/strategies.html it says:
Permission for ACCESS_COARSE_LOCATION allows access only to
NETWORK_PROVIDER.
I dont actually understand why this API doesn't give user current coordinates without location being enabled. In my opinion, if I use COARSE_LOCATİON instead of FINE_LOCATION, API should not use location.
I am also trying "Basic Location Sample" at https://github.com/googlesamples/android-play-location/tree/master/BasicLocationSample
You are requesting for user's LOCATION it may be with FINE LOCATION or COURSE LOCATION. User needs to AUTHORIZE the app for doing that.
The only difference is that the device will spend less energy trying to get the user's location and won't get exactly location.

Android Permissions and API Calls

can two different api calls each requiring a different permission produce the same results?
e.g. to get device coarse location, from Android documentation, it is an approximate location derived from network location.. can an app retrieve network location using another api call that does not require ACCESS_COARSE_LOCATION permission?
In other words, according to Android documentation, regarding LocationManager, "A location provider provides periodic reports on the geographical location of the device....some providers require GPS hardware and visibility to a number of satellites; others require the use of the cellular radio, or access to a specific carrier's network, or to the internet" and all requires either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions.
if an app doesn't ask for these permissions yet it asks for ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, and INTERNET can the app infer location? if so, what API calls are responsible for this to happen, I read the API guide, connectivity part, and searched the classes under android.net.wifi but could not find what would create such situation.
is there any work or a resource that groups Android api calls by required permissions?? e.g. a list of all api calls under ACCESS_COARSE_LOCATION permission, a list of all api calls under ACCESS_FINE_LOCATION permission and so on!
Hope I clearly asked my questions and thanks in advance!
According to the documentation:
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
You should take in consideration that coarse location (battery friendly) is not so precise as fine location (not battery friendly), AND usually they are required both because a user can decide to enable from device network location and disable GPS, it's your duty to optimize your app so it will not kill the battery. Information from above (and more about location) can be found here http://developer.android.com/guide/topics/location/strategies.html
the previous link has some explanations about the location, with some examples.
And for future reference, you might find this table useful http://developer.android.com/guide/topics/manifest/uses-feature-element.html#features-reference

Will Android still use GPS to pull location when only COARSE_LOCATION is requested?

I am trying to figure out if I really need to request ACCESS_FINE_LOCATION or not. I do not need really accurate coordinates. However, if cell towers or WiFi is not available, I want to be able to get a location from GPS (low accuracy is fine). But, I cannot find a clear answer in the Android documentation about this. Below is what the Android Docs say (ACCESS_COARSE_LOCATION). It tells me that requesting the coarse location gives me info from the "Cell-ID, WiFi" source and that requesting the fine permission will use GPS, but it says nothing about GPS being any type of fallback for when only the coarse location permission is requested.
public static final String ACCESS_COARSE_LOCATION
Since: API Level 1
Allows an application to access coarse (e.g., Cell-ID, WiFi) location
Constant Value: "android.permission.ACCESS_COARSE_LOCATION"
public static final String ACCESS_FINE_LOCATION
Since: API Level 1
Allows an application to access fine (e.g., GPS) location
Constant Value: "android.permission.ACCESS_FINE_LOCATION"
I think this other post and the Android documentation it references answers this question. The Android doc says the following.
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
So, if I'm reading that right, requesting ACCESS_COARSE_LOCATION can't pull from GPS because it does not request access for the GPS_PROVIDER.

Categories

Resources