2015-04-23 18 views
0

我有我的FragmentActivity擴展ActionBar.TabListener有兩個選項卡。在帶有標籤的onCreateView()中使用Google Map Fragment

在我的第一個標籤中,我試圖顯示GoogleMap

我該如何在我的onCreateView()方法中做到這一點?這是我的代碼:

public class MapFragment extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     View rootView = inflater.inflate(R.layout.fragment_map, container, false); 
     this.ctx = container.getContext(); 

     GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

     return rootView; 
    } 
} 

此代碼讓我對getMap()的errore:

方法的GetMap()是未定義的類型MapFragment

這是我的XML佈局fragment_map .xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="${relativePackage}.${activityClass}" > 

    <fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.MapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 
+0

檢查此鏈接https://forums.xamarin.com/discussion/15320/google-maps-actionbar-tabs –

+0

更改您的類名'MapFragment'是別的 – Xcihnegn

+0

您可以編輯您的問題,並張貼的XML你'MapFragment'? – shkschneider

回答

0

我願意賭你升級y我們的GooglePlayServices庫。

公共最終使用GoogleMap的GetMap()

此方法已。

改爲使用getMapAsync(OnMapReadyCallback)。該回調方法爲您提供了一個GoogleMap實例,該實例保證爲非null並且可以使用。

您現在需要使用getMapAsync(OnMapReadyCallback callback)而不是getMap()

+0

謝謝。我試圖使用getMapAsync ..如果它能幫助我,我會給你發短信! – aletede91

+0

我正在關注Google文檔[https://developers.google.com/maps/documentation/android/map](我的課程擴展了Fragment而不是FragmentActivity,因爲它是我的活動的一個選項卡),但它給了我一個'getMapAsync '。我能怎麼做? – aletede91

+0

你說錯誤?我忘了水晶球。對我來說,你應該描述的錯誤^^ – shkschneider

相關問題