我正在使用 map View 来显示几个用户的位置。我正在使用此处列出的一种方法来适本地设置 map 缩放级别以显示所有图钉。
但我遇到的问题是,当图钉遍布世界各地时,缩放级别已达到最大值,我在 map View 的顶部和底部看到了这个空白区域。
有没有办法解决这个问题,我只想让 map 网格填充该区域而不是颜色。这是图片和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=""/>
api key 不是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 代码。
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);
最佳答案
已解决!请在创建 map 后添加以下代码行。它的工作原理是在初始化后自动将 map 缩放 3 倍,您可以根据需要使用其他因子。
mapView.setBuiltInZoomControls(true);
int level = mapView.getZoomLevel();
MapController mc = mapView.getController();
mc.setZoom(level + 3);
关于android - MapView 没有全屏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9322615/