1

当我创建使用 Google 地图 API v2 的项目时,我遇到了这条线的问题。

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

据说我需要将 minSDK 设置为最小 11,但我也想在具有 android minSDK 8 (2.3.3) 的设备上使用此应用程序。有任何想法吗?或者简单地说:我如何将谷歌地图 API v2 设置为与具有 minSDK 8 的设备兼容。

谢谢

4

3 回答 3

6

使用SupportMapFragmentfrom a FragmentActivity,而不是MapFragmentfrom an Activity。要在 API 级别 11 之前的设备上使用 Fragment,您需要使用 Android Support 包的 Fragment 的反向端口(FragmentActivity来自哪里)。

于 2013-04-24T15:11:45.760 回答
2
    Fragment fragment = getSupportFragmentManager().findFragmentById(
            R.id.map);
    SupportMapFragment mapFragment = (SupportMapFragment) fragment;
    GoogleMap mMap = mapFragment.getMap();
于 2013-07-25T15:36:18.903 回答
2

http://android-er.blogspot.de/2012/12/using-supportmapfragment.html - 小例子

<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>

和:

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);
    }

}
于 2013-04-24T15:34:32.147 回答