24 |
private LocationManager locManager; |
private LocationManager locManager; |
25 |
private Context cntx; |
private Context cntx; |
26 |
|
|
|
private Location lastKnownLocation = null; |
|
27 |
private Location savedLocation = null; |
private Location savedLocation = null; |
28 |
private int satCount; |
private int satCount; |
29 |
|
|
60 |
return state; |
return state; |
61 |
} |
} |
62 |
|
|
|
public Location getLastKnownLocation() { |
|
|
return lastKnownLocation; |
|
|
} |
|
63 |
|
|
64 |
public long elapsedTime() { |
public long elapsedTime() { |
65 |
long now = android.os.SystemClock.elapsedRealtime(); |
long now = android.os.SystemClock.elapsedRealtime(); |
79 |
|
|
80 |
List<String> providers = locManager.getProviders(true); |
List<String> providers = locManager.getProviders(true); |
81 |
|
|
82 |
if (providers.size() > 0) { |
boolean hasProvider = false; |
83 |
for(String provider : providers) { |
|
84 |
Log.i("Provider", ""+provider); |
for(String provider : providers) { |
85 |
if (provider.equalsIgnoreCase("gps")) { |
if (provider.equals( LocationManager.PASSIVE_PROVIDER)) { |
86 |
locManager.addGpsStatusListener(this); |
continue; |
|
hasGps = true; |
|
|
} |
|
|
|
|
|
locManager.requestLocationUpdates(provider, 0, 0, this); |
|
|
Location tmpLastKnown = locManager.getLastKnownLocation(provider); |
|
|
if (tmpLastKnown != null) { |
|
|
saveLastKnownLocation(tmpLastKnown); |
|
|
} |
|
87 |
} |
} |
88 |
} else { |
|
89 |
|
Log.i("Provider", ""+provider); |
90 |
|
hasProvider = true; |
91 |
|
if (provider.equalsIgnoreCase("gps")) { |
92 |
|
locManager.addGpsStatusListener(this); |
93 |
|
hasGps = true; |
94 |
|
} |
95 |
|
|
96 |
|
locManager.requestLocationUpdates(provider, 0, 0, this); |
97 |
|
} |
98 |
|
|
99 |
|
if (hasProvider == false) { |
100 |
// message that no suitable provider was found |
// message that no suitable provider was found |
101 |
//hndl.sendEmptyMessage(StationList.NOPROVIDER); |
//hndl.sendEmptyMessage(StationList.NOPROVIDER); |
102 |
state = LookupStates.NOPROVIDER; |
state = LookupStates.NOPROVIDER; |
124 |
|
|
125 |
} |
} |
126 |
|
|
|
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; |
|
|
} |
|
|
} |
|
|
} |
|
127 |
|
|
128 |
public void stopSearch() |
public void stopSearch() |
129 |
{ |
{ |