--- android/TrainInfo/src/dk/thoerup/traininfo/LocationLookup.java 2009/09/29 18:24:23 354 +++ android/TrainInfo/src/dk/thoerup/traininfo/LocationLookup.java 2010/01/29 12:34:17 570 @@ -3,7 +3,6 @@ import java.util.List; import android.content.Context; -import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; @@ -18,6 +17,7 @@ Context cntx; Handler hndl; + Location lastKnownLocation = null; Location savedLocation = null; boolean isSearching = false; @@ -37,6 +37,10 @@ { return savedLocation; } + + public Location getLastKnownLocation() { + return lastKnownLocation; + } public void locateStations() { @@ -53,6 +57,10 @@ if (provider.equalsIgnoreCase("gps")) hasGps = true; locManager.requestLocationUpdates(provider, 0, 0, this); + Location tmpLastKnown = locManager.getLastKnownLocation(provider); + if (tmpLastKnown != null) { + saveLastKnownLocation(tmpLastKnown); + } } } else { // message that no suitable provider was found @@ -82,6 +90,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) {