1

Before explaining my problem, I ask that you please bear with me. I realize this question has been asked before, but I went through all S.O. posts related to this, and none of them were really able to solve my problem. I will try to be as accurate as possible:

I am simply trying to get my user's location. I have requested the appropriate permissions on the Manifest:

<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

And I have made the call to request location in two different ways:

//Get Location
        mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        try {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 360,
                    10, mLocationListener);
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 360,
                    10, mLocationListener);
        } catch (SecurityException e) {
            e.printStackTrace();
        }

Then, I instantiate my listener as such:

private final LocationListener mLocationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            Log.d("THIS IS NOT BEING CALLED", "GOT LOCATION");
                }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {

        }

        @Override
        public void onProviderEnabled(String provider) {

        }

        @Override
        public void onProviderDisabled(String provider) {

        }
    };

I also tried making that listener into a custom class "MyLocationListener" which I try to instantiate in my onCreate() method on my activity.

Furthermore, I checked that my GPS was on, both by checking settings and by using the Maps app.

None of this has worked for me. Is there anything else that I might be missing?

Thanks in advance for your help.

Jacobo Koenig
  • 11,728
  • 9
  • 40
  • 75
  • Is that a `LocationListener` from the `android.location.LocationListener` package or from some external library? Those overridden methods suggest that you have implemented some other `LocationListener` than the correct one. Check your `import` statements. – Markus Kauppinen Nov 09 '16 at 16:07
  • import android.location.LocationListener; The other overrides are from the Firebase library.. I cleaned them up. – Jacobo Koenig Nov 09 '16 at 16:15
  • mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 360, 10, mLocationListener); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 360, 10, mLocationListener); are the same why? – Alessandro Verona Nov 09 '16 at 16:27
  • typo.. the second is actually NETWORK_PROVIDER – Jacobo Koenig Nov 09 '16 at 16:37
  • Check [this one](http://stackoverflow.com/a/37203191/5392118). – Burak Cakir Nov 10 '16 at 06:19
  • I think minimum distance parameter should be float, so assign it like 10f. I resolved the same issue by doing so. Hope It may help some one – Janmenjaya Jul 06 '20 at 04:50

0 Answers0