--- android/TrainInfo/src/dk/thoerup/traininfo/LocationLookup.java 2009/10/29 13:01:24 487 +++ android/TrainInfo/src/dk/thoerup/traininfo/LocationLookup.java 2009/10/29 13:42:57 488 @@ -17,6 +17,7 @@ Context cntx; Handler hndl; + Location lastKnownLocation = null; Location savedLocation = null; boolean isSearching = false; @@ -36,6 +37,10 @@ { return savedLocation; } + + public Location getLastKnownLocation() { + return lastKnownLocation; + } public void locateStations() { @@ -52,6 +57,8 @@ if (provider.equalsIgnoreCase("gps")) hasGps = true; locManager.requestLocationUpdates(provider, 0, 0, this); + + saveLastKnownLocation(locManager.getLastKnownLocation(provider)); } } else { // message that no suitable provider was found @@ -81,6 +88,16 @@ hndl.sendEmptyMessage(StationList.GOTLOCATION); } + private void saveLastKnownLocation(Location loc) { + if (lastKnownLocation == null) { + lastKnownLocation = loc; + } else { + if (loc.getTime() > lastKnownLocation.getTime()) {//if loc is more recent than saved + lastKnownLocation = loc; + } + } + } + public void stopSearch() { if (isSearching) {