Android 再次打开屏幕后,地图视图完全显示
我的布局中的MapView存在以下问题: 一旦添加,它显示按钮,谷歌标志,网格,但没有地图。为了使它可见,我必须先关闭屏幕,然后再打开屏幕。有什么问题吗 这是我的密码Android 再次打开屏幕后,地图视图完全显示,android,android-maps-v2,Android,Android Maps V2,我的布局中的MapView存在以下问题: 一旦添加,它显示按钮,谷歌标志,网格,但没有地图。为了使它可见,我必须先关闭屏幕,然后再打开屏幕。有什么问题吗 这是我的密码 mapView = (MapView) geo.findViewById(R.id.map_view); mapView.onCreate(savedInstanceState); mapView.getMapAsync(this); final LocationManager lm = (Loca
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"));
}
});
}
将“OnMapReadyCallback”应用于您的活动或您正在使用的内容 然后在你的onMapready方法中
@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);
}
}
将“OnMapReadyCallback”应用于您的活动或您正在使用的内容 然后在你的onMapready方法中
@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);
}
}
我解决了在onCreateView期间初始化映射,然后将其添加到用户交互请求上的问题我解决了在onCreateView期间初始化映射,然后将其添加到用户交互请求上的问题我这样做了,但在我的片段上放上一个已准备好的,并且按照建议实现它并没有显示任何内容。至少在它显示网格之前。所以我试着把mapView.onResume()放进去;作为onMapReady方法的最后说明,现在地图显示。。。但这很奇怪,我也不明白为什么…我尝试将地图插入到片段布局xml中,而不是将其进行简单的膨胀,结果成功了。因此,问题似乎与在运行时膨胀新布局并将其附加到片段布局有关。有人可以帮我开始使用数字膨胀的aproach?@tassadar SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager();getMapAsync(这个);在布局xml文件中使用此选项,确保您已授予internet访问权限,并且您的类实现了onmapreadycallbacks。我这样做了,但将onMapReady放在我的片段上,并且按照建议实现它不会显示任何内容。至少在它显示网格之前。所以我试着把mapView.onResume()放进去;作为onMapReady方法的最后说明,现在地图显示。。。但这很奇怪,我也不明白为什么…我尝试将地图插入到片段布局xml中,而不是将其进行简单的膨胀,结果成功了。因此,问题似乎与在运行时膨胀新布局并将其附加到片段布局有关。有人可以帮我开始使用数字膨胀的aproach?@tassadar SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager();getMapAsync(这个);在布局xml文件中使用此选项,确保您已授予internet访问权限,并且您的类在MapReadyCallbacks上实现