In Version 2 Map view does not show map

后端 未结 18 1747
星月不相逢
星月不相逢 2020-12-14 18:07

Map Activity doesn\'t showing map, it\'s appear as just white screen with zoom control buttons. Manifest File like this :



        
18条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 18:44

    I got this problem using MapView

    fragment_map.xml

    
    
    
    

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        String message = getArguments().getString(EXTRA_MESSAGE);
        v = inflater.inflate(R.layout.map_f, container, false);
        vh = new ViewHolder();
        assetHandler = new AssetHandler(getActivity());
        vh.mapView=assetHandler.mapViewHandler.set(v,R.id.mapview);
        vh.mapView.onCreate(savedInstanceState);
    
        vh.mapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                googleMap.setMyLocationEnabled(true);
                // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
                try {
                    MapsInitializer.initialize(getActivity());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        return v;
    }
    
    
    @Override
    public void onResume() {
        super.onResume();
        vh.mapView.onResume();
    
    
    }
    
    @Override
    public void onPause() {
        vh.mapView.onPause();
        super.onPause();
    }
    
    @Override
    public void onDestroy() {
        vh.mapView.onDestroy();
        super.onDestroy();
    }
    
    @Override
    public void onLowMemory() {
        super.onLowMemory();
        vh.mapView.onLowMemory();
    }
    

    I noticed if the LifeCycle methods are not implemented, you will not be able to see the map as well. hope this is hopeful for some.

提交回复
热议问题