重新亮屏后MapView显示完整

MapView show completly after screen turned on again

我的布局中的 MapView 存在这个问题:

添加后会显示按钮、google 徽标、网格但没有地图。为了使其可见,我必须关闭屏幕然后再打开。有什么问题?

这是我的代码

    mapView = (MapView) geo.findViewById(R.id.map_view);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(this);
    final LocationManager lm = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
    lastKnownLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if(lastKnownLocation == null) {
        askLocationRefreshInitMapView(lm);
    } else {
        if((System.currentTimeMillis() - lastKnownLocation.getTime()) > THIRTY_MINUTES) {
            askLocationRefreshInitMapView(lm);
        } else {
            initMapView(lastKnownLocation);
        }
    }



private void initMapView(final Location location) {
    lastKnownLocation = location;
    // Gets to GoogleMap from the MapView and does initialization stuff
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(GoogleMap map) {
            map.getUiSettings().setMyLocationButtonEnabled(false);
            map.setMyLocationEnabled(true);

            // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
            try {
                MapsInitializer.initialize(getActivity());
            } catch (Exception e) {
                e.printStackTrace();
            }

            // Updates the location and zoom of the MapView
            if(location != null) {
                CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 10);
                map.moveCamera(cameraUpdate);
                map.animateCamera(cameraUpdate);
            }
            map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
        }
    });
}

将 'OnMapReadyCallback' 应用到您的 activity 或您正在使用的任何东西 然后在你的 onMapready 方法中

@Override
    public void onMapReady(GoogleMap googleMap) {
        MapsInitializer.initialize(context);
        gMap=googleMap;
     if (mapView != null) {
                // Initialise the MapView
                mapView.onCreate(null);
                // Set the map ready callback to receive the GoogleMap object
                mapView.getMapAsync(this);
            }
    }    

我解决了在 onCreateView 期间初始化地图,然后将其添加到 UserInteraction 请求中的问题