Is there a way through the android maps API, where I can detect the map center after pan animation has completed? I want to use this information to load markers from a server dynamically. Thanks BD
I also have been looking for a "did end drag" solution that detects the map center at the moment exactly after the map ended moving. I haven't found it, so I've made this simple implementation that did work fine:
private class MyMapView extends MapView {
private GeoPoint lastMapCenter;
private boolean isTouchEnded;
private boolean isFirstComputeScroll;
public MyMapView(Context context, String apiKey) {
super(context, apiKey);
this.lastMapCenter = new GeoPoint(0, 0);
this.isTouchEnded = false;
this.isFirstComputeScroll = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
this.isTouchEnded = false;
else if (event.getAction() == MotionEvent.ACTION_UP)
this.isTouchEnded = true;
else if (event.getAction() == MotionEvent.ACTION_MOVE)
this.isFirstComputeScroll = true;
return super.onTouchEvent(event);
}
@Override
public void computeScroll() {
super.computeScroll();
if (this.isTouchEnded &&
this.lastMapCenter.equals(this.getMapCenter()) &&
this.isFirstComputeScroll) {
// here you use this.getMapCenter() (e.g. call onEndDrag method)
this.isFirstComputeScroll = false;
}
else
this.lastMapCenter = this.getMapCenter();
}
}
That's it, I hope it helps! o/