2013-08-01 33 views
1

我已经开发了使用谷歌地图版本2的简单地图应用程序。它在支持Android 4.0的设备上工作正常,但不能在Android 2.3(API 10)中运行。现在我需要从API级别10支持相同的应用程序。如何从API级别10转换应用程序支持?Android 2.3中的地图版本2

我的应用程序支持“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(); 
      ........ 
     } 
} 

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

+0

如果是在4.0工作正常,请确认您的设备2.3安装谷歌播放服务。 –

+0

使用'SupportMapFragment'作为*支持库的一部分*作为向后兼容的一部分分发 –

回答

4

你提到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; 

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

检查主题开发人员指南上面的线

+0

谢谢,它的工作原理,你节省了我的时间。低版本可以支持所有功能在4.0s中支持哪些功能? –

+0

@murali_ma很高兴它有帮助。高兴地帮助 – Raghunandan

+0

@murali_ma如果它有助于接受答案 – Raghunandan

1

变化

<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 
+1

感谢您的帮助。 –

+0

@murali_ma欢迎:) –

+1

谢谢,它适合我 – mahdi

相关问题