android - MapView 没有全屏显示

标签 android google-maps android-maps android-mapview

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

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

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

enter image description here

<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/

相关文章:

java - Android透明Fragment/GoogleMap

android - ID、标签 null 或父 ID 与 com.google.android.gms.maps.MapFragment 的另一个 fragment 重复

android - 点击 Android 谷歌地图上的图标时获取完整的详细信息

android - 修改 libusb 以接受文件描述符

android - 在双摄像头手机中只用一个镜头拍摄照片?

iphone - 通过链接到 Google map (以 KML 作为查询)打开 iPhone map 应用程序

android - 当设备处于深度 sleep (打瞌睡)模式时,Geofence 未决 Intent 触发太迟

android - 如何在设备在 android 中移动时在谷歌地图上移动标记(当前标记)

Android 应用程序启动器图标大小问题

Android wifi数据包嗅探器