Note that there are some explanatory texts on larger screens.

plurals
  1. POGPS_PROVIDER unable to get location update
    text
    copied!<p>I have a code that gets location using GPS_PROVIDER. If GPS is disabled, it will get location using NETWORK_PROVIDER. Code:</p> <pre><code>private static long MIN_TIME = 1 * 5 * 1000; // 5 seconds private static final long MIN_DISTANCE = 1; // 1 meter protected LocationManager location_manager; protected Location location; public void startLocationService() { location_manager = (LocationManager) context.getSystemService(LOCATION_SERVICE); location_manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,MIN_TIME,MIN_DISTANCE, this); location_manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIME,MIN_DISTANCE, this); location = location_manager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null) { location = location_manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } @Override public void onLocationChanged(Location location) { // Updates the class's location variable this.location = location; } </code></pre> <p>This worked fine for days, but JUST recently, my onLocationChanged function has not been getting called in the past 3 days. I literally drove around so that it could detect my new location, but the coordinates I'm getting in my "location" variable is a cached one that's 3 days old.</p> <p>When I turn off GPS in Android setting, my app is able to correctly determine my location using NETWORK_PROVIDER. But when I turn GPS back on, the app then returns my 3-day old cached coordinates, and my onLocationChanged function never gets called (even when I'm outside). </p> <p>Strangely, the Google Maps app is able to get the correct coordinates regardless of whether GPS is on or off. </p> <p>Does anyone know what could be wrong? And why is it that Google Maps can properly get location updates using just GPS (and not Network) when my app can't? Does Google Map app use something else?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload