Es gibt keinen einfachen Weg, dies zu tun. Ich kann Ihnen jedoch helfen.
Erstens, hier ist ein Geschenk von einer meiner persönlichen Utility-Klassen, Tween.java:
import android.os.Handler;
public class Tween {
public static interface TweenCallback {
public void onTick(float time, long duration);
public void onFinished();
}
long start;
long duration;
Handler handler;
TweenCallback callback;
public Tween(TweenCallback callback) {
handler = new Handler();
this.callback = callback;
}
public void start(final int duration) {
start = android.os.SystemClock.uptimeMillis();
this.duration = duration;
tickRunnable.run();
}
public void stop() {
handler.removeCallbacks(tickRunnable);
}
Runnable tickRunnable= new Runnable() {
public void run() {
long now = android.os.SystemClock.uptimeMillis();
float time = now - start;
boolean finished = (time >= duration);
if (finished) {
time = duration;
}
callback.onTick(time, duration);
if (!finished) {
handler.post(tickRunnable);
}
else {
callback.onFinished();
}
}
};
//
// Tweening functions. The 4 parameters are :
//
// t - time, ranges from 0 to d
// b - begin, i.e. the initial value for the quantity being changed over time
// c - change, the amount b will be changed by at the end
// d - duration, of the transition, normally in milliseconds.
//
// All were adapted from http://jstween.sourceforge.net/Tween.js
//
public static float strongEaseInOut(float t, float b, float c, float d) {
t/=d/2;
if (t < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
}
public static float regularEaseIn(float t, float b, float c, float d) {
return c*(t/=d)*t + b;
}
public static float strongEaseIn(float t, float b, float c, float d) {
return c*(t/=d)*t*t*t*t + b;
}
}
Was ich empfehlen Sie verwenden ist MapController.zoomToSpan()
in Verbindung mit einem Tween ... hier einige komplett ungeprüfter Code, der funktionieren sollte, vielleicht mit einem Tweak oder zwei, Sie übergeben es einfach das Ziel lat & lon erstreckt sich. :
public void slowZoom(int latE6spanTarget, int lonE6spanTarget) {
final float initialLatE6span = mapView.getLatitudeSpan();
final float initialLonE6span = mapView.getLongitudeSpan();
final float latSpanChange = (float)(latE6spanTarget - initialLatE6span);
final float lonSpanChange = (float)(lonE6spanTarget - initialLonE6span);
Tween tween = new Tween(new Tween.TweenCallback() {
public void onTick(float time, long duration) {
float latSpan = Tween.strongEaseIn(time, initialLatE6span, latSpanChange, duration);
float lonSpan = Tween.strongEaseIn(time, initialLonE6span, lonSpanChange, duration);
mapView.getController().zoomToSpan((int)latSpan, (int)lonSpan);
}
public void onFinished() {
}
});
tween.start(5000);
}
Es ist ein großer Vorteil der Geschwindigkeit es animiert genannt haben: Die Menge nutzloser geladener Bilder ist reduziert. Wenn man mit den Beispielen arbeitet, die @ 1ka und @Reuben bereitstellen, würde dies dazu führen, dass viele Bitmap-Ladeanrufe auf einem (möglichen) 3G/UMTS-Netzwerk nur 350 ms später weggeworfen werden. Das ist eine Verschwendung von Bandbreite und manchmal reines Geld vom Benutzer. Auch die Google-Karte im PC-Browser funktioniert so und jeder ist daran gewöhnt. Niemand erwartet, dass beim Wechseln des angezeigten Standorts bereits eine Karte geladen ist. – WarrenFaith