0

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

Pragadees
  • 71
  • 1
  • 12
  • If it worked yesterday..and if you haven't changed anything it should work.. may be you are not getting GPS signal at your current position. – Emil Jun 25 '15 at 08:17
  • Do you get an error or just no more values in the GPS coordinates ? Maybe it comes from your connection on the phone no? – LBes Jun 25 '15 at 08:17
  • 1
    Calling getLastKnownLocation() doesn't actually make a location request. It will return null often, this is documented behavior. Register a location listener, that will request your current location from the OS. – Daniel Nugent Jun 25 '15 at 08:18

2 Answers2

1

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/

Community
  • 1
  • 1
Anil Meenugu
  • 1,411
  • 1
  • 11
  • 16
-1

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.

  • Except he never mentioned using virtual box ... This is definitely not an answer and you'd be better off asking in the comments whether it could be that he is using virtual box. Down vote – LBes Jun 25 '15 at 08:21