的問題是舊的,但有沒有一個明確的答案,所以我會後我的:
我用這個片段每天。這將處理地圖視圖剛剛創建的情況。事實上,它可能會發生,你想放大到一個邊界框作爲地圖的開始行爲。如果您在顯示視圖之前調用此方法,則視圖準備就緒後,將立即註冊偵聽器以執行縮放。
map
是我的MapView
public void zoomToBounds(final BoundingBox box) {
if (map.getHeight() > 0) {
map.zoomToBoundingBox(box, true);
} else {
ViewTreeObserver vto = map.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
map.zoomToBoundingBox(box, true);
ViewTreeObserver vto2 = map.getViewTreeObserver();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
vto2.removeGlobalOnLayoutListener(this);
} else {
vto2.removeOnGlobalLayoutListener(this);
}
}
});
}
}
下面是如何從GeoPoints
public BoundingBox computeArea(ArrayList<GeoPoint> points) {
double nord = 0, sud = 0, ovest = 0, est = 0;
for (int i = 0; i < points.size(); i++) {
if (points.get(i) == null) continue;
double lat = points.get(i).getLatitude();
double lon = points.get(i).getLongitude();
if ((i == 0) || (lat > nord)) nord = lat;
if ((i == 0) || (lat < sud)) sud = lat;
if ((i == 0) || (lon < ovest)) ovest = lon;
if ((i == 0) || (lon > est)) est = lon;
}
return new BoundingBox(nord, est, sud, ovest);
}
名單得到boundingBox的你找到解決辦法嗎? – Bikash
@bikash我沒有,但你可能想看看新版本的OSMDroid,他們可能已經修復了這個問題。 – syntagma