Check if location speed and accuracy are available.

This commit is contained in:
Jimmy Shih
2013-07-11 14:38:09 -07:00
parent 4b6c9a875b
commit e7e671c1ff
5 changed files with 14 additions and 8 deletions
@@ -107,7 +107,9 @@ public class MapOverlay {
public CachedLocation(Location location) {
this.valid = LocationUtils.isValidLocation(location);
this.latLng = valid ? new LatLng(location.getLatitude(), location.getLongitude()) : null;
this.speed = (int) Math.floor(location.getSpeed() * UnitConversions.MS_TO_KMH);
this.speed = location.hasSpeed() ? (int) Math.floor(
location.getSpeed() * UnitConversions.MS_TO_KMH)
: -1;
}
/**
@@ -714,7 +714,8 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
hasGoodFix = false;
} else {
hasFix = !LocationUtils.isLocationOld(currentLocation);
hasGoodFix = currentLocation.getAccuracy() <= recordingGpsAccuracy;
hasGoodFix = currentLocation.hasAccuracy()
&& currentLocation.getAccuracy() < recordingGpsAccuracy;
}
if (!hasFix) {
message = getString(R.string.gps_wait_for_signal);
@@ -148,7 +148,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
if (lastLocation != null) {
boolean hasFix = !LocationUtils.isLocationOld(lastLocation);
boolean hasGoodFix = lastLocation.getAccuracy() <= recordingGpsAccuracy;
boolean hasGoodFix = lastLocation.hasAccuracy()
&& lastLocation.getAccuracy() < recordingGpsAccuracy;
if (!hasFix || !hasGoodFix) {
lastLocation = null;
@@ -888,7 +888,7 @@ public class TrackRecordingService extends Service {
return;
}
if (location.getAccuracy() > recordingGpsAccuracy) {
if (!location.hasAccuracy() || location.getAccuracy() >= recordingGpsAccuracy) {
Log.d(TAG, "Ignore onLocationChangedAsync. Poor accuracy.");
return;
}
@@ -192,16 +192,18 @@ public class TripStatisticsUpdater {
currentSegment.addMovingTime(movingTime);
// Update grade
if (lastLocation.hasAltitude() && location.hasAltitude()) {
if (location.hasAltitude() && lastLocation.hasAltitude()) {
float run = lastLocation.distanceTo(location);
double rise = location.getAltitude() - lastLocation.getAltitude();
updateGrade(run, rise);
}
// Update max speed
updateSpeed(
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
if (location.hasSpeed() && lastLocation.hasSpeed()) {
updateSpeed(
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
}
lastLocation = location;
lastMovingLocation = location;
}