Open GoogleCodeExporter opened 9 years ago
I had this problem every time I tried to use zoomToSpan.
This was always in Activity onCreate().
Then i noticed that the MapView has a similar method:
zoomToBoundingBox(BoundingBoxE6 boundingBox)
The documentation for zoomToBoundingBox states:
"Zoom the map to enclose the specified bounding box, as closely as possible.
Must be called after display layout is complete, or screen dimensions are not
known, and will always zoom to center of zoom level 0."
My MapView always has dimensions of zero pixels square in onCreate, so using
some code i found on StackOverflow i came up with this solution:
public void fitMapToMarkers() {
Log.d("B4A", "MapView has height of " + mMapView.getHeight());
if (mMapView.getHeight() > 0) {
Log.d("B4A", "Debug #1a");
// mMapView.getController().zoomToSpan(mOverlayItemsBounds); // does not work but no ANR
mMapView.zoomToBoundingBox(mOverlayItemsBounds); // works
} else {
// wait for layout
ViewTreeObserver vto1 = mMapView.getViewTreeObserver();
vto1.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Log.d("B4A", "Debug #2a");
// mMapView.getController().zoomToSpan(mOverlayItemsBounds); // does not work but no ANR
mMapView.zoomToBoundingBox(mOverlayItemsBounds); // works
ViewTreeObserver vto2 = mMapView.getViewTreeObserver();
vto2.removeGlobalOnLayoutListener(this);
}
});
}
}
mOverlayItemsBounds is an ArrayList of GeoPoints.
Original comment by warwo...@gmail.com
on 18 Mar 2012 at 12:38
I tested MyMath.getNextSquareNumberAbove(float factor) by throwing in values of
1,10,100,1000 and so on and noticed that it would work perfectly fine with 1E9
and freeze (loop forever) with 1E10.
Original comment by bastis...@googlemail.com
on 5 Jun 2012 at 1:36
Original issue reported on code.google.com by
iforpow...@gmail.com
on 22 Feb 2012 at 6:18Attachments: