2012-02-17 79 views
1

我使用的MapView顯示幾個用戶的位置。我使用一個在這裏列出來設置適當的地圖縮放級別來顯示所有的引腳的方法。的MapView不採取全屏

但有問題的IM是,當引腳是世界各地的縮放級別刷爆了,我得到的MapView的頂部和底部的這個空白。

有沒有辦法解決這個問題,我只想地圖電網,以填補該區域,而不是顏色。這裏是圖片和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密鑰不是爲debig證書爲什麼的MapView只顯示網格。但你可以看到白色的空間。一旦我們放大,這個改變。我需要檢查我的縮放邏輯。我認爲最大縮小仍將填充可用空間。

我認爲這是與變焦。從谷歌文檔。

zoomToSpan

嘗試調整地圖的縮放比例,以便給定 跨度緯度和經度將被顯示。由於縮放可能只能達到離散的水平,並且由於地圖 的長寬比可能與給定的比例不匹配,因此擬合的質量可能會有所不同。我們保證的唯一的事情是,在縮放之後,新緯度或新經度中的至少一個將從 的2倍因子的相應參數內。

我認爲長寬比是問題。有沒有更可靠的方法來做到這一點。這是我的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); 

回答

0

在地圖視圖之前使用線性佈局。

+0

我的地圖視圖在屬性爲填充父項的線性佈局中。我只是沒有包括在XML中。 – blessenm 2012-02-17 05:26:34

1

已解決!請在創建地圖後添加下面的代碼行。其工作原理是通過汽車的3倍縮放地圖初始化後,如果你願意,你可以使用其他因素。

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