谷歌地图Android LatLngBounds

谷歌地图Android LatLngBounds,android,google-maps,google-maps-android-api-2,Android,Google Maps,Google Maps Android Api 2,在添加标记后,我将使用以下代码缩放到地图上的最大缩放级别。它可以工作,但只有在500毫秒延迟内才能运行。如果它把它拿出来,它就不工作了。我知道我错过了一些明显的东西,但我不知道我错过了什么。有人能告诉我在没有Runnable的情况下,我需要把LatLngBounds代码放在哪里才能工作吗 // Expand our Zoom to fit all markers LatLngBounds.Builder builder = new LatLngBounds.Builder();

在添加标记后,我将使用以下代码缩放到地图上的最大缩放级别。它可以工作,但只有在500毫秒延迟内才能运行。如果它把它拿出来,它就不工作了。我知道我错过了一些明显的东西,但我不知道我错过了什么。有人能告诉我在没有Runnable的情况下,我需要把LatLngBounds代码放在哪里才能工作吗

// Expand our Zoom to fit all markers
        LatLngBounds.Builder builder = new LatLngBounds.Builder();

        //the include method will calculate the min and max bound.
        builder.include(myLocationPin.getPosition());
        builder.include(placeLocationPin.getPosition());

        final LatLngBounds bounds = builder.build();

        final int zoomWidth = getResources().getDisplayMetrics().widthPixels;
        final int zoomHeight = getResources().getDisplayMetrics().heightPixels;
        final int zoomPadding = (int) (zoomWidth * 0.10); // offset from edges of the map 12% of screen

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,zoomWidth,zoomHeight,zoomPadding));
            }
        }, 500);

在缩放地图之前,您可能需要等待地图加载回调:

@Override
public void onMapLoaded() {
if (mMap != null) {
 map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,zoomWidth,zoomHeight,zoomPadding)); }}

在缩放地图之前,您可能需要等待地图加载回调:

@Override
public void onMapLoaded() {
if (mMap != null) {
 map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,zoomWidth,zoomHeight,zoomPadding)); }}

您需要立即显示地图:

mMapView.onResume();

您需要立即显示地图:

mMapView.onResume();