Android MapView MapController stopAnimation not st

2019-07-21 08:40发布

问题:

well, i'm developing a geolocation app in Android. On first run we center the map at the current location, then the user can zoom and pan freedomly, but we have a button that animates the map and centers it back to the actual position.

The problem is that this just happens when the map is static: if the user scrolls the map and leaves it scrolling by inertia, this button won't work until the animation is stopped.

Here's the code.

mapView.getController().stopAnimation(false); //this aint working as expected
mapView.getController().animateTo(myLocationOverlay.getMyLocation());

Thanks.

回答1:

This works for me:

public void centerCurrentClickHandler(View v) {
    if (hasCurrentPosition) {
        GeoPoint point = new GeoPoint(currentLatitudeE6, currentLongitudeE6);
        mapController.animateTo(point);
    }
}

public void centerFlagClickHandler(View v) {
    if (hasPushpinPosition) {
        GeoPoint point = new GeoPoint(pushpinLatitudeE6, pushpinLongitudeE6);
        mapController.animateTo(point);
    }
}