RyanInBinary
RyanInBinary

Reputation: 1547

Zooming and animating to point mapview android

So in my current application, I want to zoom to a lat/long point, but also use the animateTo (or equivalent) to make sure the screen is properly centered. Currently I'm just doing something like this:

_mapController.animateTo(new GeoPoint(googleLat, googleLng));


            // Smooth zoom handler
            int zoomLevel = _mapView.getZoomLevel();
            int targetZoomLevel = AppConstants.MAP_ZOOM_LEVEL_SWITCH;
            long delay = 0;
            while (zoomLevel++ < targetZoomLevel) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                       _mapController.zoomIn();
                    }
                }, delay);

                delay += 350; // Change this to whatever is good on the device
            }

This kind of works, but what happens is that my thread starts, BEFORE the 'animate to' finishes, so it zooms in and then 'jumps' to display the correct center geoPoint. Is there a way to smoothly 'drill down' to a certain zoom level, as well as move to a geoPoint at the same time? Similar to how the official Googl eMaps application zooms to an address after you've searched for it is what I'm looking to do.

Upvotes: 0

Views: 1149

Answers (1)

CSmith
CSmith

Reputation: 13458

I would do something like:

_mapController.animateTo(new GeoPoint(googleLat,googleLong), new Runnable() {
 public void run()
 {
  _mapController.zoomIn ();
 }
});

This will achieve a pan-then-zoom effect. You can try your same logic inside the runnable to perform multi-step zoomIn's.

Upvotes: 1

Related Questions