Google maps v2 on android devices with minSDK below 11

匿名 (未验证) 提交于 2019-12-03 02:29:01

问题:

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

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

It's says that I need to set minSDK to be minimum 11, but I want to use this application also on devices with android minSDK 8 (2.3.3). Any ideas? Or simply: How I can set google maps API v2 to be compatible with devices with minSDK 8.

Thanks

回答1:

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



回答2:

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


回答3:

    Fragment fragment = getSupportFragmentManager().findFragmentById(             R.id.map);     SupportMapFragment mapFragment = (SupportMapFragment) fragment;     GoogleMap mMap = mapFragment.getMap();


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!