Skip to content

Commit

Permalink
Adding last location tracking variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed May 5, 2017
1 parent 70e5e3e commit 530744e
Showing 1 changed file with 29 additions and 3 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 530744e

Please sign in to comment.