getController() setZoom no effect code example

Example 1: getController() setZoom no effect

if (searchedLocationFrom != null && searchedLocationTo != null) { // center

            int lat1 = (int) (searchedLocationFrom.getLatitude() * 1E6);
            int lon1 = (int) (searchedLocationFrom.getLongitude() * 1E6);
            int lat2 = (int) (searchedLocationTo.getLatitude() * 1E6);
            int lon2 = (int) (searchedLocationTo.getLongitude() * 1E6);

            // mapController.setZoom(13);
            mapController.zoomToSpan((lat1 > lat2 ? lat1 - lat2 : lat2
                    - lat1), (lon1 > lon2 ? lon1 - lon2 : lon2 - lon1));
            int z = mapView.getZoomLevel();
            mapController.setZoom(z > 1 ? z - 1 : z);
            mapController
                    .setCenter(new GeoPoint(lat1 - ((lat1 - lat2) / 2),
                            lon1 - ((lon1 - lon2) / 2)));
        }

Example 2: getController() setZoom no effect

private void setRegionOfMap(){
    final LinearLayout layout = (LinearLayout)findViewById(R.id.outdoor_maps_linearlayout);
    final ViewTreeObserver vto = layout.getViewTreeObserver(); 
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
        @Override 
        public void onGlobalLayout() { 
            layout.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
            MapView mapView = (MapView)layout.findViewById(R.id.mapview);
            mapView.getController().setCenter(mCenterPoint);
            mapView.getController().zoomToSpan(mLatSpan, mLongSpan);
        } 
    });
}

Tags:

Css Example