diff --git a/src/com/audacious_software/passive_data_kit/generators/device/Location.java b/src/com/audacious_software/passive_data_kit/generators/device/Location.java index 7428d53..b85f6d2 100755 --- a/src/com/audacious_software/passive_data_kit/generators/device/Location.java +++ b/src/com/audacious_software/passive_data_kit/generators/device/Location.java @@ -113,7 +113,6 @@ public class Location extends Generator implements GoogleApiClient.ConnectionCal private static Location sInstance = null; private GoogleApiClient mGoogleApiClient = null; - private android.location.Location mLastLocation = null; private long mUpdateInterval = 60000; private SQLiteDatabase mDatabase = null; @@ -317,6 +316,8 @@ public void onLocationChanged(android.location.Location location) { if (location == null) return; + Log.e("PDK", "LOCATION CHANGED: " + location); + long now = System.currentTimeMillis(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.mContext); @@ -926,10 +927,31 @@ public android.location.Location getLastKnownLocation() { return location; } - if (this.mLastLocation != null) { - return this.mLastLocation; + android.location.Location lastLocation = null; + + Cursor c = this.mDatabase.query(Location.TABLE_HISTORY, null, null, null, null, null, Location.HISTORY_OBSERVED + " DESC"); + + if (c.moveToNext()) { + double latitude = c.getDouble(c.getColumnIndex(Location.HISTORY_LATITUDE)); + double longitude = c.getDouble(c.getColumnIndex(Location.HISTORY_LONGITUDE)); + + lastLocation = new android.location.Location("Passive-Data-Kit"); + lastLocation.setLatitude(latitude); + lastLocation.setLongitude(longitude); } + c.close(); + + + + if (lastLocation != null) { + Log.e("PDK", "RETURNING LAST SAVED LOCATION: " + lastLocation); + + return lastLocation; + } + + Log.e("PDK", "FETCHING LOCATION"); + LocationManager locations = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); android.location.Location last = null; @@ -939,8 +961,12 @@ public android.location.Location getLastKnownLocation() { last = locations.getLastKnownLocation(LocationManager.GPS_PROVIDER); + Log.e("PDK", "GPS LAST: " + last); + if (last == null) { last = locations.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + + Log.e("PDK", "NET LAST: " + last); } }