2016-03-23 18 views
0

我这个问题,我的布局里面的MapView:MapView的演出后完全地画面再次打开

添加一次它显示按钮,谷歌的标志,格但没有地图。为了使它可见,我必须关闭屏幕然后再打开。有什么问题?

这里我的代码

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")); 
     } 
    }); 
} 

回答

1

我解决初始化onCreateView,然后在地图上什么都你使用 然后在您的onMapready方法将它添加到UserInteraction请求上

0

实施“OnMapReadyCallback”到您的活动或

@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); 
      } 
    }  
+0

我做了它,但在我的片段上放置了MapReady并按照建议的那样实现了它,但没有显示任何内容。至少在展示网格之前。所以我试图把mapView.onResume();作为onMapReady方法的最后一次尝试,现在地图显示......但它很奇怪,我不明白为什么... – tassadar

+0

我试图插入片段布局xml内的地图,而不是充气它dinamically,它的工作原理。所以这个问题似乎与在运行时膨胀一个新布局并将其附加到碎片布局有关。有人可以帮助我开始处理夸大其辞的事情吗? – tassadar

+0

@tassadar SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.where_are_they_map); mapFragment.getMapAsync(this); –

相关问题