2016-04-09 15 views
1

私は2つのウィンドウを持つスライディングタブフラグメントを持ち、最初にGoogleマップビューを含んでいます。フラグメントは正常に動作し、Googleのフラグメントも表示されますが、マップはロードされません。グリッド線とGoogleロゴが表示された空白の地図のみが表示されます。私のコードで何が間違っていますか?Google Mapはフラグメント内に読み込まれません

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

レイアウト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> 
+0

白SupportMapFragmentの回答を使用する必要があります。 – Amitsharma

答えて

1

私はあなたのMapViewがcom.google.android.gms.maps.SupportMapFragmentの名前を与えると何をしようとして理解していません。それは意味をなさない。

フラグメントにマップを配置する場合は、フラグメントに互換性ライブラリを使用する場合は、MapFragmentまたはSupportMapFragmentを使用する必要があります。これらのフラグメントは、フラグメントのスペース内のマップの表示を管理します。

ApiDemosサンプルプロジェクトには、サンプルプロジェクトの使用例があります。 SupportMapViewフラグメントを宣言するHere is a layout

関連する問題