MapFragment和Mapview API v2

时间:2013-04-22 11:15:46

标签: android map android-mapview mapfragment

我遇到了问题,我可以使用MapView并正确查看地图:

 <com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>

但是当我使用MapFragment时,应用程序崩溃了......错误地膨胀类片段:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

main.java只是:

public class situar_mapav3 extends android.support.v4.app.FragmentActivity{

    public situar_mapav3() {


    }
        @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
     }

有什么想法吗?感谢。

2 个答案:

答案 0 :(得分:3)

您必须扩展com.google.android.gms.maps.SupportMapFragment而不是android.support.v4.app.FragmentActivity

答案 1 :(得分:0)

尝试使用这种布局,并且plz发布logcat日志,将有助于更好地理解问题

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapParent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
相关问题