2015-04-23 80 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

相关问题