我已经使用Google Map版本2开发了简单的Map应用程序。 在支持Android 4.0的设备上运行良好,但无法在Android 2.3(API 10)中运行。 现在,我需要支持API级别10的同一应用程序。如何转换API级别10的应用程序支持?
我的应用程序受“ google-play-services_lib ”支持。
我的代码示例。
main.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"/>
您的活动还必须扩展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;
检查主题开发人员指南上方的行
改成
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
和
extends FragmentActivity
和
mMap =((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();mMap