diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java index bf35f2a40..e49ace669 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java @@ -237,7 +237,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask { int count = cursor.getCount(); List locations = new ArrayList(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 { diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java index 11a5fb040..f0d8503c9 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java @@ -244,7 +244,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { int count = cursor.getCount(); List locations = new ArrayList(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; }