forked from upstream-mirrors/OpenTracks
Bug fix. Make sure the start marker location is valid when sending to Google Maps and Google Fusion Tables.
This commit is contained in:
+12
-9
@@ -237,7 +237,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
||||
|
||||
int count = cursor.getCount();
|
||||
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
||||
Location lastLocation = null;
|
||||
Location lastValidLocation = null;
|
||||
boolean sentStartMarker = false;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
cursor.moveToPosition(i);
|
||||
@@ -245,14 +246,15 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
||||
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
||||
locations.add(location);
|
||||
|
||||
if (i == 0) {
|
||||
// Create a start marker
|
||||
String name = context.getString(R.string.marker_label_start, track.getName());
|
||||
createNewPoint(fusiontables, tableId, name, "", location, MARKER_TYPE_START);
|
||||
if (LocationUtils.isValidLocation(location)) {
|
||||
lastValidLocation = location;
|
||||
}
|
||||
|
||||
if (LocationUtils.isValidLocation(location)) {
|
||||
lastLocation = location;
|
||||
if (!sentStartMarker && lastValidLocation != null) {
|
||||
// Create a start marker
|
||||
String name = context.getString(R.string.marker_label_start, track.getName());
|
||||
createNewPoint(fusiontables, tableId, name, "", lastValidLocation, MARKER_TYPE_START);
|
||||
sentStartMarker = true;
|
||||
}
|
||||
|
||||
// Upload periodically
|
||||
@@ -274,11 +276,12 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
||||
}
|
||||
|
||||
// Create an end marker
|
||||
if (lastLocation != null) {
|
||||
if (lastValidLocation != null) {
|
||||
String name = context.getString(R.string.marker_label_end, track.getName());
|
||||
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
||||
String description = descriptionGenerator.generateTrackDescription(track, null, null, true);
|
||||
createNewPoint(fusiontables, tableId, name, description, lastLocation, MARKER_TYPE_END);
|
||||
createNewPoint(
|
||||
fusiontables, tableId, name, description, lastValidLocation, MARKER_TYPE_END);
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
|
||||
@@ -244,7 +244,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
|
||||
int count = cursor.getCount();
|
||||
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
||||
Location lastLocation = null;
|
||||
Location lastValidLocation = null;
|
||||
boolean sentStartMarker = false;
|
||||
|
||||
// For chart server, limit the number of elevation readings to 250.
|
||||
int elevationSamplingFrequency = Math.max(1, (int) (count / 250.0));
|
||||
@@ -261,13 +262,18 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
||||
locations.add(location);
|
||||
|
||||
if (i == 0) {
|
||||
if (LocationUtils.isValidLocation(location)) {
|
||||
lastValidLocation = location;
|
||||
}
|
||||
|
||||
if (!sentStartMarker && lastValidLocation != null) {
|
||||
// Create a start marker
|
||||
if (!uploadMarker(context.getString(R.string.marker_label_start, track.getName()), "",
|
||||
START_ICON_URL, location)) {
|
||||
START_ICON_URL, lastValidLocation)) {
|
||||
Log.d(TAG, "Unable to create a start marker");
|
||||
return false;
|
||||
}
|
||||
sentStartMarker = true;
|
||||
}
|
||||
|
||||
tripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||
@@ -275,9 +281,6 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||
}
|
||||
if (LocationUtils.isValidLocation(location)) {
|
||||
lastLocation = location;
|
||||
}
|
||||
|
||||
// Upload periodically
|
||||
int readCount = i + 1;
|
||||
@@ -298,14 +301,14 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
}
|
||||
|
||||
// Create an end marker
|
||||
if (lastLocation != null) {
|
||||
if (lastValidLocation != null) {
|
||||
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
||||
track.setDescription(
|
||||
descriptionGenerator.generateTrackDescription(track, distances, elevations, true));
|
||||
if (!uploadMarker(context.getString(R.string.marker_label_end, track.getName()),
|
||||
track.getDescription(), END_ICON_URL, lastLocation)) {
|
||||
track.getDescription(), END_ICON_URL, lastValidLocation)) {
|
||||
Log.d(TAG, "Unable to create an end marker");
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user