2013-05-09 48 views
0

我的getMap()方法返回null。为什么这个方法返回null?我查看了Android开发人员文档以确保我正确使用此方法。这里我使用来获取地图的代码行:getMap()返回null

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.myMapView)).getMap(); 

这里是我的Java代码:

private ProjectionProxy proxy = new ProjectionProxy(); 

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle load) { 
    super.onCreate(load); 

    setContentView(R.layout.fragment_ride_tracking); 

    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.myMapView)).getMap(); 

    Log.e("RideTracking", "Google Map VALUE:"+mMap); 

    if (mMap != null) { 
     proxy.setProjection(mMap.getProjection()); 
    } 

以下是一个特定的代码我的XML代码:

<fragment 
    android:id="@+id/myMapView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:name="com.google.android.gms.maps.MapFragment"/> 

这里是logcat的输出:

05-09 12:49:34.282: W/GooglePlayServicesUtil(5928): Google Play services out of date. Requires 3027100 but found 2012110 
05-09 12:49:34.282: E/RideTracking(5928): Google Map VALUE:null 
05-09 12:49:34.302: E/OGT.GPSLoggerServiceManager(5928): No GPSLoggerRemote service connected to this manager 
05-09 12:49:34.322: W/dalvikvm(5928): Unable to resolve superclass of Lcom/android/gpstracker/viewer/FixedMyLocationOverlay; (2174) 
05-09 12:49:34.322: W/dalvikvm(5928): Link of class 'Lcom/android/gpstracker/viewer/FixedMyLocationOverlay;' failed 
05-09 12:49:34.322: W/dalvikvm(5928): Unable to resolve superclass of Lcom/android/gpstracker/viewer/FixedMyLocationOverlay; (2174) 

任何帮助将不胜感激!

+0

您是在模拟器上测试吗?我有一段时间没有尝试过,但地图服务曾经在仿真器上不可用。 – 2013-05-09 18:14:50

+0

是的,我试过了。没有运气。 – user268397 2013-05-09 18:15:20

+0

抱歉改变了我的评论。我的意思是模拟器不是调试器。 – 2013-05-09 18:16:11

回答

0

尝试这样

GoogleMap googleMap; 

MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.myMapView); 


googleMap = fm.getMap(); 

改变它,如果你是在模拟器中运行它,你需要安装两个APK文件(Read this Post)

如果您已经调整了仿真器和安装的两个文件已经那么你有到Google_Play_services_lib改为第4版(download it here)

刚刚与旧版本#更换新Go​​ogle_Play_services_lib 4精选文摘中e并将其引用到该项目中。

+0

我有版本6的Google Play服务库。这足够好吗? – user268397 2013-05-09 19:22:40

+0

将其更改为rev 4仅用于模拟器测试 – Neo 2013-05-10 04:32:42

+0

如果要在Emulator上运行地图,则必须通过adb安装这两个APK文件'adb install com.android.vending.apk adb install com.google.android .gms.apk” – Neo 2013-05-10 07:41:38

0

显然,线

05-09 12:49:34.282: W/GooglePlayServicesUtil(5928): Google Play services out of date. Requires 3027100 but found 2012110 

告诉我们,为什么在地图不是实例。

你需要有谷歌的最新版本的播放设备上的服务,否则你会得到:
This app won't run without Google Play Services
getMap()将返回null