I am using following code to display a map in Xamarin.Android:
private SupportMapFragment mapFragment;
private GoogleMap map;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
mapFragment = SupportFragmentManager.FindFragmentByTag ("map") as SupportMapFragment;
if (mapFragment == null) {
GoogleMapOptions options = new GoogleMapOptions ()
.InvokeCompassEnabled (true)
.InvokeMapType (GoogleMap.MapTypeNone)
.InvokeZoomControlsEnabled (false);
FragmentTransaction frx = SupportFragmentManager.BeginTransaction ();
mapFragment = SupportMapFragment.NewInstance (options);
frx.Add (Resource.Id.map,mapFragment,"map");
frx.Commit ();
}
if (map == null)
map = mapFragment.Map;
CircleOptions circle = new CircleOptions ();
circle.InvokeCenter (new LatLng(18.5203,73.8567));
circle.InvokeRadius (1000);
map.AddCircle (circle);
and my AXML is
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
After successful deployment on device, it is giving me an exception on line map.AddCircle (circle);
as System.NullReferenceException
has been thrown Object Reference is not set to an instance of an Object
.
What am I doing wrong? Is there something needed to be initialized?