我有一个带有两个窗口的滑动标签片段,第一个包含一个谷歌地图视图。片段工作正常,Google片段也会显示,但地图不会加载。仅显示带有网格线和Google徽标的空白地图。我的代码出了什么问题?
public class CardFragment extends Fragment implements OnMapReadyCallback{
private static final String ARG_POSITION = "position";
private int position;
GoogleMap mMap;
Geocoder coder;
public static CardFragment newInstance(int position) {
CardFragment f = new CardFragment();
Bundle b = new Bundle();
b.putInt(ARG_POSITION, position);
f.setArguments(b);
return f;
}
public static MapsFragment newInstance(String s) {
Bundle args = new Bundle();
args.putString("value", s);
MapsFragment result = new MapsFragment();
result.setArguments(args);
return result;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
position = getArguments().getInt(ARG_POSITION);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(position == 0){
View rootView = inflater.inflate(R.layout.maps_frag,container,false);
ButterKnife.inject(this, rootView);
ViewCompat.setElevation(rootView, 50);
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getContext()) == ConnectionResult.SUCCESS) {
MapView mapView = (MapView) rootView.findViewById(R.id.mymap);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
return rootView;
} else {
View rootView = inflater.inflate(R.layout.list_frag,container,false);
ViewCompat.setElevation(rootView, 50);
return rootView;
}
@Override
public void onMapReady(final GoogleMap googleMap) {
mMap = googleMap;
coder = new Geocoder(this.getContext());
p1 = null;
}
layout maps_frag
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardBackgroundColor="@android:color/white">
<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swagishmap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.locustapps.ingredientsapp.MapsActivity"/>
</android.support.v7.widget.CardView>
</FrameLayout>