我使用的是從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 ;
}
}
}
你加入這個網絡? class =「com.google.android.gms.maps.SupportMapFragment」 – TheFlash
我不明白,這加在哪裏?我沒有像你在評論中寫的任何代碼。哪裏應該添加這個? –
在作爲屬性。 –
TheFlash