关于android:MapView不全屏

MapView not taking full screen

我正在使用地图视图来显示几个用户的位置。我正在使用此处列出的一种方法来适当地设置地图缩放级别以显示所有图钉。

但我遇到的问题是,当图钉遍布世界各地时,缩放级别已达到最大值,我在地图视图的顶部和底部得到了这个空白。

有没有办法解决这个问题,我只希望地图网格填充该区域而不是颜色。这是图片和xml

enter

1
2
3
4
5
6
<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=""/>

api 密钥不适用于 debig 证书,这就是为什么 mapview 只显示网格的原因。但是你可以看到空白。一旦我们放大,这种情况就会改变。我需要检查我的缩放逻辑吗?我认为最大缩小仍然会填满可用空间。

我认为这与缩放有关。来自谷歌文档。

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.

我认为长宽比是问题所在。有没有更可靠的方法来做到这一点。这是我的 java 代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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);

解决了!请在创建地图后添加以下代码行。它通过在初始化后将地图自动缩放 3 倍来工作,如果您愿意,您可以使用其他因子。

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

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