Google Map loading issue in android listview

后端 未结 4 1076
刺人心
刺人心 2021-01-15 12:10

I am trying to show mapview on my listview. Map cannot load in listview. If i touch the map view, map will load. If i scroll the listview mapview goes to unloaded initial st

4条回答
  •  长发绾君心
    2021-01-15 12:51

    I came across the same problem, and using your code and other stack topics I came up with this way of doing it

    mapView.onCreate(savedInstanceState);
    mapView.onResume();
    mapView.getMapAsync(
            new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googlemap) {
            final GoogleMap map = googlemap;
            map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    
            MapsInitializer.initialize(context);
    
            map.setMyLocationEnabled(true);
            map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    
            LatLng sydney = new LatLng(-33.873, 151.206);
            String markerTitle = "Sydney";
            String snippetTitle = "Lovely city";
    
            if (markerTitle != null && snippetTitle != null) {
                map.addMarker(new MarkerOptions()
                        .title(markerTitle)
                        .snippet(snippetTitle)
                        .position(sydney));
            }
    
            map.setMyLocationEnabled(true);
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney2, 13));
    
        }
    }
    );
    

    1) You need to call onResume(); on mapView so it loads properly 2) Use .getMapAsync, getMap is deprecated

    You will be able to zoom in with a double tap :)

提交回复
热议问题