17 |
Context cntx; |
Context cntx; |
18 |
Handler hndl; |
Handler hndl; |
19 |
|
|
20 |
|
Location lastKnownLocation = null; |
21 |
Location savedLocation = null; |
Location savedLocation = null; |
22 |
|
|
23 |
boolean isSearching = false; |
boolean isSearching = false; |
37 |
{ |
{ |
38 |
return savedLocation; |
return savedLocation; |
39 |
} |
} |
40 |
|
|
41 |
|
public Location getLastKnownLocation() { |
42 |
|
return lastKnownLocation; |
43 |
|
} |
44 |
|
|
45 |
public void locateStations() { |
public void locateStations() { |
46 |
|
|
57 |
if (provider.equalsIgnoreCase("gps")) |
if (provider.equalsIgnoreCase("gps")) |
58 |
hasGps = true; |
hasGps = true; |
59 |
locManager.requestLocationUpdates(provider, 0, 0, this); |
locManager.requestLocationUpdates(provider, 0, 0, this); |
60 |
|
Location tmpLastKnown = locManager.getLastKnownLocation(provider); |
61 |
|
if (tmpLastKnown != null) { |
62 |
|
saveLastKnownLocation(tmpLastKnown); |
63 |
|
} |
64 |
} |
} |
65 |
} else { |
} else { |
66 |
// message that no suitable provider was found |
// message that no suitable provider was found |
81 |
if (hasGps) { |
if (hasGps) { |
82 |
if (!location.getProvider().equals("gps")) { |
if (!location.getProvider().equals("gps")) { |
83 |
return; // at least give the gps a chance |
return; // at least give the gps a chance |
84 |
} else if (location.getAccuracy() > 256) { |
} else if (location.getAccuracy() > 512) { |
85 |
return; //if we have a gps provider lets wait for a more precise fix |
return; //if we have a gps provider lets wait for a more precise fix |
86 |
} |
} |
87 |
|
|
90 |
hndl.sendEmptyMessage(StationList.GOTLOCATION); |
hndl.sendEmptyMessage(StationList.GOTLOCATION); |
91 |
} |
} |
92 |
|
|
93 |
|
private void saveLastKnownLocation(Location loc) { |
94 |
|
if (lastKnownLocation == null) { |
95 |
|
lastKnownLocation = loc; |
96 |
|
} else { |
97 |
|
if (loc.getTime() > lastKnownLocation.getTime()) {//if loc is more recent than saved |
98 |
|
lastKnownLocation = loc; |
99 |
|
} |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
public void stopSearch() |
public void stopSearch() |
104 |
{ |
{ |
105 |
if (isSearching) { |
if (isSearching) { |