Single track playback

There was a known trajectory data, click on the playback button, the car automatically forward movement along the route, finished playing is over

public class MoveSingleThread extends Thread{
private List<LatLng> mLatLngList;
private Marker mCarMarker;
public MoveSingleThread(List<LatLng> latLngs, Marker marker) {
super();
mLatLngList = latLngs;
mCarMarker = marker;
}

@Override
public void RUN () {
super.run ();
}
public void moveTrack () {
// The first for loop is used to calculate how many go
int STEP = 0;
for (int I = 0; I <mLatLngList .size () -. 1; I ++) {
of LatLng the startPoint = mLatLngList.get (I);
of LatLng endPoint, mLatLngList.get = (I +. 1);
Double Slope = getSlope (the startPoint, endPoint,);
// Flag is not positive (set up forward)
boolean isReverse = (startPoint.latitude> endPoint.latitude);
Double xMoveDistance = isReverse getXMoveDistance (Slope):? -1 * getXMoveDistance (Slope);
// should latitude and longitude simultaneous processing
for (double j = startPoint.latitude; ((J> = endPoint.latitude) ^ isReverse);! J =
J - xMoveDistance) {
STEP ++;
}
}

// the distance, the trajectory calculation interval animation
double mTimeInterval = 0; // track playback timestamp
IF (! TextUtils.isEmpty (mDistance)) {
a float totalDistance = Float.parseFloat as (mDistance) * 1000;
IF (totalDistance <= 500 ) {
mTimeInterval = 1000.0 / STEP;
} the else IF (totalDistance> 500 && totalDistance <= 7500) {
mTimeInterval = 2.0 * totalDistance / STEP;
} the else {
mTimeInterval = 15000.0 / STEP;
}
}

// while (true) {
for (int i = 0; i < mLatLngList.size() - 1; i++) {
if (stopFlag) {
stopFlag = false;
break;
}
mIsCarMoveing = true;
LatLng startPoint = mLatLngList.get(i);
LatLng endPoint = mLatLngList.get(i + 1);
mCarMarker.setPosition(startPoint);
mCarMarker.setRotateAngle((float) getAngle(startPoint, endPoint));
double slope = getSlope(startPoint, endPoint);
// 是不是正向的标示(向上设为正向)
boolean isReverse = (startPoint.latitude > endPoint.latitude);
double intercept = getInterception(slope, startPoint);
double xMoveDistance = isReverse ? getXMoveDistance(slope) : -1 * getXMoveDistance(slope);
// 应该对经纬度同时处理
msleep 0 = Double;
for (Double J = startPoint.latitude; ((J> = endPoint.latitude) ^ isReverse);! J =
J - xMoveDistance) {
of LatLng latLng = null;
IF (Slope = Double.MAX_VALUE!) {
of latLng = new new latLng (J, (J - Intercept) / Slope);
// latLng of latLng new new = (J, K);
} {the else
latLng of latLng new new = (J, startPoint.longitude);
}
mCarMarker.setPosition (latLng) ;
// If the interval is less than 1 millisecond, then skip this sleep, the sleep time is accumulated until one millisecond: loses precision
IF (mTimeInterval <1) {
msleep + = mTimeInterval;
IF (msleep> = 1) {
SystemClock.sleep ((Long) msleep);
msleep = 0;
}
} the else
SystemClock.sleep ((Long) mTimeInterval);
}
}
}
}

Guess you like

Origin www.cnblogs.com/ly570/p/11369960.html