1

我使用的是從xamarin工作室這個示例代碼顯示谷歌在我的項目android版2地圖Android版地圖:支持分片管理器總是返回null在谷歌2

_mapFragment = SupportFragmentManager.FindFragmentByTag("map") as SupportMapFragment; 
      if (_mapFragment == null) 
      { 
       GoogleMapOptions mapOptions = new GoogleMapOptions() 
        .InvokeMapType(GoogleMap.MapTypeSatellite) 
         .InvokeZoomControlsEnabled(false) 
         .InvokeCompassEnabled(true); 

       FragmentTransaction fragTx = SupportFragmentManager.BeginTransaction(); 
       _mapFragment = SupportMapFragment.NewInstance(mapOptions); 
       fragTx.Add(Resource.Id.googleMap , _mapFragment, "map"); 
       fragTx.Commit(); 
      } 

,這是我的佈局

<FrameLayout 
    android:id="@+id/googleMap" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

但它總是返回null。

我也運行xamrin的樣本。雖然它工作良好。但現在它不工作。沒有錯誤或例外。只是_mapFragment爲空。

從哪裏可以這樣?

編輯

我改變佈局代碼:

<fragment 
    android:id="@+id/googleMap" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" /> 

和代碼的第一行是:

_mapFragment = SupportFragmentManager.FindFragmentById (Resource .Id.googleMap) as SupportMapFragment; 

目前,FragmentManager不返回null。但地圖不加載,但片段是白色的頁面,而不是縮小和放大作品。

我用得到這個地圖代碼,但映射片段回報null

private void SetupMapIfNeeded() 
    { 
     if (mapView == null) 
     { 
      mapView = _mapFragment.Map; 
      if (mapView != null) 
      { 
       mapView .MapType =1; 
       mapView .MyLocationEnabled = true ; 

      } 
     } 
    } 
+0

你加入這個網絡? class =「com.google.android.gms.maps.SupportMapFragment」 – TheFlash

+0

我不明白,這加在哪裏?我沒有像你在評論中寫的任何代碼。哪裏應該添加這個? –

+0

作爲屬性。 – TheFlash

回答

0

關於第二個問題:現在

,該FragmentManager不返回null。但地圖不加載,但片段是白色的頁面,而不是縮小和放大作品。

此問題通常來自於引用google-play-service庫時出現的問題。 看看這個博客文章中,我寫了一篇關於如何將谷歌地圖整合應用程序,特別是第3步:

Google Maps API V2

這樣做的另一個原因可能是你沒有配置谷歌API控制檯正確,所以我建議你看看這個指南,以及:

Google Maps API V2 Key

另一個原因可能導致這個是,如果你在你的權限某種問題清單文件。您也可以查看所需權限的第一個指南。

+0

謝謝回覆,我想你應該是對的。其實Xamarin有特定的方式來嘗試谷歌播放庫。他描述了它https://github.com/xamarin/monodroid-samples/tree/master/MapsAndLocationDemo_v2。 porobably我有這個問題。但是我不知道。我將googleplayservices添加到propeject,但你問題是生活 –

+0

請注意,可能不會在您的REGOIN中提供GOOGLE地圖(例如中東國家) –

0

也許關鍵是不正確的。你可以嘗試以下的事情:

  • 確保你使用正確的數據包名稱,比如this
  • 允許使用的清單

+0

感謝您的回覆。兩者都是正確的 –