Zooming and animating to point mapview android

本秂侑毒 提交于 2019-12-11 19:59:55

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11694905/zooming-and-animating-to-point-mapview-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!