我使用谷歌地图版本 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;
检查 Developer's guide 主题上方的行
关于android - Android 2.3 中的 map 版本 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17992551/