Move faster when animating route. Try to get to each point in 2 steps.
This commit is contained in:
parent
dace41d8f8
commit
eb8b5b6eea
1 changed files with 13 additions and 10 deletions
|
@ -23,22 +23,20 @@ public class RouteAnimation {
|
||||||
public void run() {
|
public void run() {
|
||||||
final List<Location> directions = new ArrayList<Location>(
|
final List<Location> directions = new ArrayList<Location>(
|
||||||
routingHelper.getCurrentRoute());
|
routingHelper.getCurrentRoute());
|
||||||
Location current = null;
|
Location current = directions.isEmpty() ? null : new Location(directions.remove(0));
|
||||||
Location prev = null;
|
Location prev = null;
|
||||||
float meters = 20.0f;
|
float meters = metersToGoInFiveSteps(directions, current);
|
||||||
while (!directions.isEmpty() && routeAnimation != null) {
|
while (!directions.isEmpty() && routeAnimation != null) {
|
||||||
if (current == null) {
|
if (current.distanceTo(directions.get(0)) > meters) {
|
||||||
current = new Location(directions.remove(0));
|
current = LatLonUtils.middleLocation(current,
|
||||||
|
directions.get(0), meters);
|
||||||
} else {
|
} else {
|
||||||
if (current.distanceTo(directions.get(0)) > meters) {
|
current = new Location(directions.remove(0));
|
||||||
current = LatLonUtils.middleLocation(current,
|
meters = metersToGoInFiveSteps(directions, current);
|
||||||
directions.get(0), meters);
|
|
||||||
} else {
|
|
||||||
current = new Location(directions.remove(0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
current.setSpeed(meters);
|
current.setSpeed(meters);
|
||||||
current.setTime(System.currentTimeMillis());
|
current.setTime(System.currentTimeMillis());
|
||||||
|
current.setAccuracy(5);
|
||||||
if (prev != null) {
|
if (prev != null) {
|
||||||
current.setBearing(prev.bearingTo(current));
|
current.setBearing(prev.bearingTo(current));
|
||||||
}
|
}
|
||||||
|
@ -57,6 +55,11 @@ public class RouteAnimation {
|
||||||
prev = current;
|
prev = current;
|
||||||
}
|
}
|
||||||
RouteAnimation.this.stop();
|
RouteAnimation.this.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private float metersToGoInFiveSteps(
|
||||||
|
final List<Location> directions, Location current) {
|
||||||
|
return directions.isEmpty() ? 20.0f : Math.max(20.0f, current.distanceTo(directions.get(0)) / 2 );
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
routeAnimation.start();
|
routeAnimation.start();
|
||||||
|
|
Loading…
Reference in a new issue