Skip to content

Commit

Permalink
fix current location maximumAge
Browse files Browse the repository at this point in the history
  • Loading branch information
mauron85 committed May 28, 2018
1 parent f34f9a4 commit 515f621
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/marianhello/bgloc/LocationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ public void onPermissionDenied() {
*/
@SuppressLint("MissingPermission")
public Location getCurrentLocationNoCheck(int timeout, long maximumAge, boolean enableHighAccuracy) throws InterruptedException, TimeoutException {
final long minLocationTime = System.currentTimeMillis() - maximumAge;
final android.location.LocationManager locationManager = (android.location.LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

Location lastKnownGPSLocation = locationManager.getLastKnownLocation(android.location.LocationManager.GPS_PROVIDER);
if (lastKnownGPSLocation != null && lastKnownGPSLocation.getTime() <= maximumAge) {
if (lastKnownGPSLocation != null && lastKnownGPSLocation.getTime() >= minLocationTime) {
return lastKnownGPSLocation;
}

Location lastKnownNetworkLocation = locationManager.getLastKnownLocation(android.location.LocationManager.NETWORK_PROVIDER);
if (lastKnownNetworkLocation != null && lastKnownNetworkLocation.getTime() <= maximumAge) {
if (lastKnownNetworkLocation != null && lastKnownNetworkLocation.getTime() >= minLocationTime) {
return lastKnownNetworkLocation;
}

Expand Down

0 comments on commit 515f621

Please sign in to comment.