简体   繁体   中英

MapView not taking full screen

I am using the mapview to show the positions of couple of users. I am using one the methods listed here to set the map zoom level appropriately to show all the pins.

But the problem im having is that when the pins are all around the world the zoom levels is maxed out and I get this white space on the top and bottom of the mapview.

Is there a way to fix this, I just want the maps grid to fill that area instead of the color. Here is the picture and xml

在此处输入图片说明

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"    
    android:id="@+id/mapview"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="#061a2f"
    android:clickable="true" android:apiKey=""/>

The api key is not for the debig certificate that why the mapview only shows the grid. But you can see the white space. This changes once we zoom in. Will i need to check my zoom logic. I thought the max zoom out will still fill the available space.

I think it has something to do with the zooming. From the google docs.

zoomToSpan

Attempts to adjust the zoom of the map so that the given span of latitude and longitude will be displayed. Because the zoom can only achieve discrete levels, and because the aspect ratio of the map may not match the ratio given, the quality of the fit may vary. The only thing we guarantee is that, after the zoom, at least one of the new latitude or the new longitude will be within a factor of 2 from the corresponding parameter.

I think the aspect ratio is the problem. Is there a more reliable way to do this. Here is my java code.

for(Visitor visitor:mVisitors){
    LiveMapOverlay overlay = new LiveMapOverlay(new 
            PinDrawable(mContext,color),mMapView);
GeoPoint point = new GeoPoint(
            (int)(Double.valueOf(visitor.visitorInfo.latitude) * 1E6)                            
            ,(int)(Double.valueOf(visitor.visitorInfo.longitude) * 1E6));
minLatitude = minLatitude < point.getLatitudeE6() ? minLatitude :   
            point.getLatitudeE6();
maxLatitude = maxLatitude > point.getLatitudeE6() ? maxLatitude : 
            point.getLatitudeE6();
minLongitude = minLongitude< point.getLongitudeE6()? minLongitude: 
            point.getLongitudeE6();
maxLongitude = maxLongitude> point.getLongitudeE6()? maxLongitude: 
            point.getLongitudeE6();
}
mMapView.getController().setCenter(new GeoPoint((maxLatitude + minLatitude)/2 , 
        (minLongitude + maxLongitude)/2));
mMapView.getController().zoomToSpan(maxLatitude - minLatitude, maxLongitude - 
        minLongitude);

Resolved! please add the lines of code below after creating your map. It works by auto zooming the map by a factor of 3 after initialization you can use other factors if you wish.

mapView.setBuiltInZoomControls(true); 
int level = mapView.getZoomLevel();
MapController mc = mapView.getController();
mc.setZoom(level + 3);

在地图视图之前使用线性布局。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM