Move faster when animating route. Try to get to each point in 2 steps.

This commit is contained in:
Pavol Zibrita 2012-01-18 04:02:28 +01:00
parent dace41d8f8
commit eb8b5b6eea

View file

@ -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) {
current = new Location(directions.remove(0));
} else {
if (current.distanceTo(directions.get(0)) > meters) { if (current.distanceTo(directions.get(0)) > meters) {
current = LatLonUtils.middleLocation(current, current = LatLonUtils.middleLocation(current,
directions.get(0), meters); directions.get(0), meters);
} else { } else {
current = new Location(directions.remove(0)); current = new Location(directions.remove(0));
} meters = metersToGoInFiveSteps(directions, current);
} }
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();