I would like location information to be available to my App, from GPS if available, and if not from other means such as Wifi.
Location info works fine with GPS, but if I turn
Settings->Personal->Location Mode = Battery Saving
to exercise a non GPS scenario, or just run the App where these is no access to GPS, location information is no longer available to the App.
In my code this test returns false when GPS is not available :
string Provider = LocationManager.GpsProvider;
if (m_LocMgr.IsProviderEnabled(Provider))
Log.Info("location available");
else
Log.Info("location NOT available");
My manifest.xml is set up as follows :
...
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
...
Any ideas please. How can I enable location services when GPS is not available
The answer was simply to enable the Network provider in addition the GPS one.
Provider = LocationManager.NetworkProvider;
if (m_LocMgr.IsProviderEnabled(Provider))
m_LocMgr.RequestLocationUpdates(Provider, 2000, 1, this);
I had misread the permissions documentation. Just because it says that if you use Fine (GPS) permissions you implicitly get Coarse (Network) permissions, does NOT mean that you dont need to enable them both in code.
Related
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.
I am trying to access GPS in my Mobile
using the following code
locationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
loc1 =locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
till yesterday it was working fine now app is not fecthing gps
i have enabled permission in manifest
LocationManager
This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to fire an application-specified Intent when the device enters the proximity of a given geographical location.
You do not instantiate this class directly; instead, retrieve it through Context.getSystemService(Context.LOCATION_SERVICE).
Unless noted, all Location API methods require the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permissions. 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 Manifest File :
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
How do I get the current GPS location programmatically in Android?
http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/
I have had the same problem. I had to re-check my virtualbox network settings. Please double check your settings before assuming your code is the problem.
I am currently working with GPS in my android application.My questions are, 1.Is GPRS needed to get gps coordinates,if want to get coordinates without GPS? 2.What are the settings need to be enabled to to work with gps coordinates using network?
You want geographical coordinates as pair: latitude, longitude. (not GPS coordinates)
Such coordinates and other attributes can be delivered either by GPS, WLAN or Cell-Tower locating.
For WLAN and Cell-Tower (Network) locating you need an internet connection.
For GPS Locationg Provider, ususally you don't need any network (GSM) but there are some Android phones that are strange designed, such that GPS does not work without having an Internet connection while starting GPS.
If you want network locating, you can explicitly set the Location Provider. Set it to NETWORK_PROVIDER:
if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
Is GPRS needed to get gps coordinates
Answer: Not necessary if you are not using map.
But you have to use following permissions to work with GPS.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
What are the settings need to be enabled to to work with gps coordinates using network
Only enable your wi-fi and GPS on device.
To 1.: GPRS and GPS do not have anything in common. GPRS is a protocol for mobile internet, whereas GPS is for positioning you're phone. GPS doesn't need internet to work!
Anyways, most smartphones nowadays have Assisted GPS (A-GPS), which basically works as normal GPS (without any internet connection), but CAN retrieve information about the GPS satellites via internet for a faster location fix. GPS should still work without any internet connection as far as I know, but maybe there are really provider out there, who messed with the protocol so badly.
Long story short: GPS doesn't need internet!
To 2.: as I mentioned above, you don't need any internet for GPS, so that
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
should work.
But you're question sounds like you wanna obtain coordinates via network positioning. In that case you would need
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
But: ACCESS_COARSE_LOCATION is already implied by ACCESS_FINE_LOCATION
In my Android application I'm willing to use GPS locations.
What are the main permissions that I should included in android
manifest file in order to use GPS locations.
In case of lost the GPS signal strength, is there any way to triangulate the position using mobile networks.
Thank you!
The main permissions you need are android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
Only fine location will allow you access to gps data, and allows you access to everything else coarse location gives. You can use the methods of the LocationManager to acquire location data from gps and cell tower sources already, you do not have to work out this information yourself.
If you are targeting API Level 21 (5.0) or higher, you may also need this:
<uses-feature android:name="android.hardware.location.gps" />
This permission should allow your app to use location services through the devices GPS, wifi, and cell towers. Just plop it in your manifest wherever you put your permissions, and it should do the trick. You can find all the other permissions here: (http://developer.android.com/reference/android/Manifest.permission.html)
Here is the code:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I had the same issue and noticed that the code was requesting high accuracy but the manifest had course permissions. I changed it to fine and the error no longer occurs.
Make sure the code and the manifest reflect the same level of accuracy requested and allowed.
So if the manifest has android.permission.ACCESS_FINE_LOCATION the application can request geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high...
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.