Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth zoom in mapview

When I use MapController.setZoom(x) and, for instance, zoom from level 5 to 15 the zoom is perform very fast and often the map tiles of the new level are not loaded.

This does not look so good to the user. Any Maps build in function to change this to a more slow zoom so tiles can be loaded, or at least almost loaded, before level 15 is reached?

Best regards

P

like image 317
per_jansson Avatar asked Dec 09 '10 12:12

per_jansson


1 Answers

A simpler way is to take advantage of the MapController.zoomIn() method that provides some simple animation for zooming a step level.

Here's some code:

    // a Quick runnable to zoom in
    int zoomLevel = mapView.getZoomLevel();
    int targetZoomLevel = 18;

    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
    }

What it does is create a sequence of delayed runnables each one of which will call zoomIn() 350ms after the previous one.

This assumes that you have a Handler attached to your main UI thread called 'handler'

:-)

like image 140
SoftWyer Avatar answered Oct 27 '22 11:10

SoftWyer