Accessing Gps issue - android

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.

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 Location Not Available when there is no GPS

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.

in android, GPS_PROVIDER works, but NETWORK_PROVIDER does not

I am building an android application.
I can get GPS coordinates fine using
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
But when I try to use the network provider (editing the line, not doing two registers)
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,0,locationListener);
I get no coordinates.
I am checking if I have coordinates doing a println(location.toString()) inside the locationListener.
Both GPS and WIFI location are enabled on the device (and, as far as I can tell, other applications manage to use WIFI location)
Am I missing something? Is there a special procedure to use NETWORK_PROVIDER ?
(I have only "fine location" permissions, but the docs explicitly say this also allows "coarse location")
gps –> (GPS, AGPS): Name of the GPS location provider. This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION.
network –> (AGPS, CellID, WiFi MACID): Name of the network location provider. This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup. Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.

GPS coordinates using network

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

Get *coarse* location from GPS provider on 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.

Categories

Resources