Trying to track down the missing end of track bug.

This commit is contained in:
Sandor Dornbush
2010-09-21 15:10:56 -07:00
parent 797de31960
commit d05c394c68
3 changed files with 36 additions and 11 deletions
@@ -1001,29 +1001,36 @@ public class MyTracksMap extends MapActivity
setSamplingFrequency(selectedTrack);
int bufferSize = 1024;
int points = 0;
while (lastSeenLocationId < selectedTrack.getStopId()) {
long tailLocationId = selectedTrack.getStopId() - 10;
while (lastSeenLocationId < (selectedTrack.getStopId() + 10)) {
cursor = providerUtils.getLocationsCursor(
selectedTrack.getId(), lastSeenLocationId, bufferSize, false);
selectedTrack.getId(), lastSeenLocationId + 1, bufferSize, false);
if (cursor != null && cursor.moveToFirst()) {
final int idColumnIdx = cursor.getColumnIndexOrThrow(
TrackPointsColumns._ID);
while (cursor.moveToNext()) {
do {
points++;
Location location = providerUtils.createLocation(cursor);
lastSeenLocationId = cursor.getLong(idColumnIdx);
// Include a point if it fits one of the following criteria:
// - Has the mod for the sampling frequency.
// - Is the first point.
// - Is the last point and we are not recording this track.
// - Is on of the last n points.
// => This is to make sure we draw the last points people are probably zoomed in to.
if (!MyTracksUtils.isValidLocation(location) ||
points % samplingFrequency == 0 ||
points == 0 ||
(recordingTrackId != selectedTrack.getId() &&
points == (totalLocations - 1))) {
lastSeenLocationId > tailLocationId) {
mapOverlay.addLocation(location);
}
}
} while (cursor.moveToNext());
} else {
// TODO this is wrong sometimes. Should just return.
if (lastSeenLocationId >= selectedTrack.getStopId()) {
cursor.close();
mapView.postInvalidate();
return;
}
lastSeenLocationId += bufferSize;
}
cursor.close();
@@ -33,6 +33,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.util.Log;
import java.util.ArrayList;
@@ -221,14 +222,31 @@ public class MyTracksOverlay extends Overlay {
}
// Get the current viewing window:
int w = mapView.getLongitudeSpan();
int h = mapView.getLatitudeSpan();
int w = mapView.getLongitudeSpan() * 2;
int h = mapView.getLatitudeSpan() * 2;
int cx = mapView.getMapCenter().getLongitudeE6();
int cy = mapView.getMapCenter().getLatitudeE6();
Rect rect = new Rect(cx - w, cy - h, cx + w, cy + h);
Log.i(MyTracksConstants.TAG,
"Found bounding box: " + rect);
Point pt = new Point();
GeoPoint upperLeft = new GeoPoint(rect.top, rect.left);
Point pUpperLeft = new Point();
mapView.getProjection().toPixels(upperLeft, pUpperLeft);
GeoPoint bottomRight = new GeoPoint(rect.bottom, rect.right);
Point pBottomRight = new Point();
mapView.getProjection().toPixels(upperLeft, pBottomRight);
Rect dispRect = new Rect(pUpperLeft.x, pUpperLeft.y,
pBottomRight.x, pBottomRight.y);
Log.i(MyTracksConstants.TAG,
"Found display box: " + rect);
canvas.drawRect(dispRect, selectedTrackPaint);
Rect displayRect;
GeoPoint geoPoint;
Location loc;
Location lastValidLocation = null;
Path path;
@@ -411,8 +411,8 @@ public class TripStatistics implements Parcelable {
* @param bottomE6 the southmost latitude reached
*/
public void setBounds(int leftE6, int topE6, int rightE6, int bottomE6) {
latitudeExtremities.set(bottomE6, topE6);
longitudeExtremities.set(leftE6, rightE6);
latitudeExtremities.set(bottomE6 / 1E6, topE6 / 1E6);
longitudeExtremities.set(leftE6 / 1E6, rightE6 / 1E6);
}
// Data manipulation methods