Forum Xamarin.Android

Adding GoogleMaps to a fragment

I am trying to add a Google Maps fragment to an app with 3 tabs at the top.

To start off:
I created a blank app and used

<fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.google.android.gms.maps.mapfragment" />

I called the following code:

        private void SetUpMap()
        {
            if (mMap == null)
            {
                FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map).GetMapAsync(this);
            }
        }



And it worked like a charm!

It did everything I wanted it to. So I figured I would do more with it and have tried to add it to a more advanced app - -I am following this tutorial:

The source code works and the app looks like this:

Image and video hosting by TinyPic

In Fragment 3 I would like to put my map but am having some issues. It works fine (for a bit) and I can click on Fragment 3 and my map shows up... but if I click out of that fragment and then try to get back into it - it throws an inflate error at the inflater.Inflate line


MainActivity - Tab adapter class:


I am just learning to use Xamarin and I'm wondering if someone can point me in the correct direction on where I should set up my map and if I leave the fragment 3 tab and come back to it how do I keep it from recreating the map?

Any advice on anything else would be appreciated as well.

Thanks

Tagged:
Sign In or Register to comment.