可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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();