From f4ca2def291378abd7cf5f504cb9e5a6c450d3ef Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sat, 7 Jan 2012 01:52:45 +0300 Subject: [PATCH] [android] Fixed invalid last location bug --- .../mapswithme/maps/location/LocationService.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/android/src/com/mapswithme/maps/location/LocationService.java b/android/src/com/mapswithme/maps/location/LocationService.java index d54f2bdec6..93d948eee5 100644 --- a/android/src/com/mapswithme/maps/location/LocationService.java +++ b/android/src/com/mapswithme/maps/location/LocationService.java @@ -158,13 +158,13 @@ public class LocationService implements LocationListener, SensorEventListener, W // @param currentBestLocation The current Location fix, to which you want to compare the new one protected boolean isBetterLocation(Location newLocation, Location currentBestLocation) { - // A new location is better than no location only if it's not too old + // A new location is thrown away if it's too old + if (java.lang.System.currentTimeMillis() - newLocation.getTime() > TWO_MINUTES) + return false; + + // A new location is better than no location if (currentBestLocation == null) - { - if (java.lang.System.currentTimeMillis() - newLocation.getTime() > TWO_MINUTES) - return false; return true; - } // Check whether the new location fix is newer or older final long timeDelta = newLocation.getTime() - currentBestLocation.getTime(); @@ -218,8 +218,6 @@ public class LocationService implements LocationListener, SensorEventListener, W { if (isBetterLocation(l, m_lastLocation)) { - m_lastLocation = l; - if (m_reportFirstUpdate) { m_reportFirstUpdate = false; @@ -235,6 +233,7 @@ public class LocationService implements LocationListener, SensorEventListener, W } notifyLocationUpdated(l.getTime(), l.getLatitude(), l.getLongitude(), l.getAccuracy()); } + m_lastLocation = l; } //@Override