android - Android 2.3 中的 map 版本 2

标签 android google-maps android-maps android-version

我使用谷歌地图版本 2 开发了简单的 map 应用程序。它在支持 Android 4.0 的设备上运行良好,但不能在 Android 2.3(API 10) 上运行。现在我需要从 API 级别 10 支持同一个应用程序。如何转换对 API 级别 10 的应用程序支持?

我的应用程序支持“google-play-services_lib”。

我的代码示例。

主.xml:

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

java代码:

    public class MainActivity extends Activity implements LocationListener{
        private GoogleMap mMap;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
           ........
       }
}

请帮助我支持 API 10(Android 2.3)。

最佳答案

你提到 API 10

您应该使用 SupportMapFragment 而不是 MapFragment

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

您的 Activity 还必须扩展 FragmentActivity

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
mMap = fm.getMap(); 

导入

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment; 

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

检查 Developer's guide 主题上方的行

关于android - Android 2.3 中的 map 版本 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17992551/

相关文章:

Android - map 无法显示

android - 使用列表、 fragment 和 map 实现选项卡的最佳方式?

android - Odex 文件与 dex 文件

android - 扩展文件 : Once the expansion files is downloaded start the Intent to next activity

android - 使用 Transition Framework 恢复或重置场景

android - 在谷歌地图项目中膨胀类 fragment 时出错

android - 如何在android中的AsyncTask中使用方法?

android - RecyclerVIew 自动滚动显示所有元素,如 News Feed 等,

javascript - 删除热图进行刷新

android - Canvas 在 Android 的 mapview 上绘制多边形