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"));
}
});
}
我做了它,但在我的片段上放置了MapReady并按照建议的那样实现了它,但没有显示任何内容。至少在展示网格之前。所以我试图把mapView.onResume();作为onMapReady方法的最后一次尝试,现在地图显示......但它很奇怪,我不明白为什么... – tassadar
我试图插入片段布局xml内的地图,而不是充气它dinamically,它的工作原理。所以这个问题似乎与在运行时膨胀一个新布局并将其附加到碎片布局有关。有人可以帮助我开始处理夸大其辞的事情吗? – tassadar
@tassadar SupportMapFragment mapFragment =(SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.where_are_they_map); mapFragment.getMapAsync(this); –