I have my own location class. I have a chance that when I search for a GPS location using my class, I get 0, 0 back.
If I look for the getLastKnown function in the location manager for GPS, I get a forced value:
public Location getGPSloc(Context c){ isGPSavailable(c); if(gps_enabled) lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, locationListenerGps); timerGPS = new Timer(); timerGPS.schedule(new GetLastLocationGPS(), 45000); return gpsLoc; }
This is the class that I am calling from outside the function, I am using this.getApplicationContext () in the call. This is GetLastLocationGPS ():
class GetLastLocationGPS extends TimerTask { @Override public void run() { lm.removeUpdates(locationListenerGps); if(gps_enabled){ gpsLoc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);} else{ gpsLoc = null; } } }
Here is the listener:
LocationListener locationListenerGps = new LocationListener() { @Override public void onLocationChanged(Location location) { timerGPS.cancel(); gpsLoc = location; lm.removeUpdates(this); } @Override public void onProviderDisabled(String provider) {} @Override public void onProviderEnabled(String provider) {} @Override public void onStatusChanged(String provider, int status, Bundle extras) {} };
When I call MyLocationInstance.getGPSloc (this.getApplicationContext ()), the return value is always 0, 0. I have a forced value of 43 43 that I sent to the emulator and appears when I connect to LocationManagerInstance.getLastKnownLocation (LM.GPS );
I do not know why this method will not get the location.
Is this because theoretically the timer still works when the call is in progress? This is the only way to get an answer. Any other ideas?
source share