0
このチュートリアルは、このサイトのhttp://www.c-sharpcorner.com/article/xamarin-android-create-google-map-with-marker/に従っています。それはMainActivityで100%動作しますが、コードをフラグメント化するとすぐに 'Object is not set to instance'というエラーメッセージが表示されます。何が問題なの?ここに私のコードは次のとおりです。FragmentManager - Xamarinの使い方
public class ViewAlert : Fragment, IOnMapReadyCallback
{
View view = null;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = inflater.Inflate(Resource.Layout.ViewAlert, container, false);
try
{
SetUpMap();
}
catch (Exception ex)
{
}
return view;
}
private void SetUpMap()
{
if (GMap == null)
{
FragmentManager.FindFragmentById<MapFragment>(Resource.Id.googlemap).GetMapAsync(this);
}
}
public void OnMapReady(GoogleMap googleMap)
{
this.GMap = googleMap;
GMap.UiSettings.ZoomControlsEnabled = true;
LatLng latlng = new LatLng(Convert.ToDouble(gpsLatitude), Convert.ToDouble(gpsLongitude));
CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 15);
GMap.MoveCamera(camera);
MarkerOptions options = new MarkerOptions()
.SetPosition(latlng)
.SetTitle("Chennai");
GMap.AddMarker(options);
}
}
エラーは、この行で発生します
FragmentManager.FindFragmentById<MapFragment>(Resource.Id.googlemap).GetMapAsync(this);
私が試した:
view.FragmentManager.FindFragmentById<MapFragment>(Resource.Id.googlemap).GetMapAsync(this);
をしかし、それは動作しませんでした。
マップはマーカーなしで読み込みます。侵入コードはマーカーを地図上に置く責任があります。
それは完全に罰金働きました。ありがとうございました –