私も同じ問題を抱えていました。onLayout() メソッドの最後で zoomToBoundingBox() 呼び出しを呼び出して対処しました。
私は MapView の独自のサブクラスを持っており、これを使用してマップ ライブラリの選択から隔離しています。このクラスには、clearPoints / addPoint / layoutPoints スタイルのインターフェイスがあります。layoutPoints() メソッド内で、ポイントのコレクションからアイテム化されたオーバーレイ レイを作成し、クラスのインスタンス メソッドに格納されるバウンディング ボックスを作成します。
public class MyMapView extends MapView {
// The bounding box around all map points
// Used to determine the correct zoom level to show everything
private int minLat = Integer.MAX_VALUE;
private int minLon = Integer.MAX_VALUE;
private int maxLat = Integer.MIN_VALUE;
private int maxLon = Integer.MIN_VALUE;
private BoundingBoxE6 boundingBox;
私の onLayout() オーバーライドは次のとおりです。
/* (non-Javadoc)
* @see org.osmdroid.views.MapView#onLayout(boolean, int, int, int, int)
*/
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
super.onLayout(arg0, arg1, arg2, arg3, arg4);
// Now that we have laid out the map view,
// zoom to any bounding box
if (this.boundingBox != null) {
this.zoomToBoundingBox(this.boundingBox);
}
}
これが最善の方法かどうかはわかりませんが、私にはうまくいくようです (ただし、ズームが少し遠すぎるように見えますが、それはまた別の問題です)。