Google maps v2 on android devices with minSDK below 11

前端 未结 3 1586
我寻月下人不归
我寻月下人不归 2021-01-16 09:51

i have problem with this line when I create project which use Google maps API v2.

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

相关标签:
3条回答
  • 2021-01-16 10:28
        Fragment fragment = getSupportFragmentManager().findFragmentById(
                R.id.map);
        SupportMapFragment mapFragment = (SupportMapFragment) fragment;
        GoogleMap mMap = mapFragment.getMap();
    
    0 讨论(0)
  • 2021-01-16 10:32

    Use SupportMapFragment from a FragmentActivity, instead of MapFragment from an Activity. To use fragments on devices older than API Level 11, you need to use the Android Support package's backport of fragments (where FragmentActivity comes from).

    0 讨论(0)
  • 2021-01-16 10:36

    http://android-er.blogspot.de/2012/12/using-supportmapfragment.html - small example

    <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=".MainActivity" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/hello_world" />
        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment"/>
    
    </RelativeLayout>
    

    AND:

    package de.meinprospekt.android.ui;
    
    import java.text.SimpleDateFormat;
    
    public class MainActivity extends FragmentActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题