I'm using this code from xamarin studio sample for showing google maps android version 2 in my project:
_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();
}
and this is my layout
<FrameLayout
android:id="@+id/googleMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
but it always return null.
I run the sample of xamrin also. while it works fine ago. but now it is not working. No errors or exceptions. just _mapFragment
is null.
from where could be this?
EDIT
I change the layout code to :
<fragment
android:id="@+id/googleMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
and the first line of code to this:
_mapFragment = SupportFragmentManager.FindFragmentById (Resource .Id.googleMap ) as SupportMapFragment;
now, the FragmentManager
not returns null. but yet the map don't loaded but yet the fragment is a white page and not zooming out and zooming in works.
I use this code for getting map, but map fragment returns null
:
private void SetupMapIfNeeded()
{
if (mapView == null)
{
mapView = _mapFragment.Map;
if (mapView != null)
{
mapView .MapType =1;
mapView .MyLocationEnabled = true ;
}
}
}