2016-03-23 20 views
0

benim layout'ta MapView ile bu sorunu ettik tamamen sonra göstermektedir. Görünür hale getirmek için ekranı kapatıp açmam gerekiyor. Sorun ne? İşteMapView ekran açıldığında tekrar

kodum

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

cevap

1

Sonra onCreateView ve sırasında haritayı başlatılıyor çözülmesi için UserInteraction istekleri üzerine ekleme

0

Uygulamak 'OnMapReadyCallback' etkinlik veya her ne size onMapready yönteminde sonra kullandığınız

@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

Bunu yaptım ama parçam üzerine onMapReady koyup önerilen hiçbir şey göstermiyor. En azından bir ızgara göstermeden önce. Bu yüzden mapView.onResume(); onMapReady yönteminin son instrunction olarak ve şimdi harita görüntüler ... ama çok garip ve neden olduğunu anlayamıyorum ... – tassadar

+0

Haritanın içine yerleştirmeye çalıştım yerine xml parçasını yerleştirmek yerine dinamik ve çalışır. Yani sorun, çalışma zamanında yeni bir düzeni şişirmek ve onu parça düzenine eklemekle ilgili gibi görünüyor. Birisi dinamik olarak şişirilmiş bir yaklaşımla çalışmama yardım edebilir mi? – tassadar

+0

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

İlgili konular