1

地理的マーカーを含むマップフラグメントをアプリに追加し、Playサービスジャーを含めましたが、マーカーコードで次のエラーが発生します。

Error: Cannot cast from Fragment to SupportMapFragment 

スニペットは次のとおりです。

GoogleMap mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        mMap.addMarker(new MarkerOptions()
                .position(new LatLng(53.271900177, -9.04889965057))
                .title("GMI alway Location"));;

これは、それを参照するための私のxml宣言です。

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

誰かが私がどこで間違っているのかについて何か考えがありますか?ありがとうブライアンJ

4

1 に答える 1

1

レイアウトでを使用している場合は、SupportFragmentManagerとクラスを使用する必要があります。FragmentActivitySupportMapFragment

したがって、のgetSupportFragmentManager()代わりにメソッドを使用してgetFragmentManager()ください。

于 2013-03-23T20:49:35.780 に答える