0

I am trying to follow the Maps API guide, but I've had this error for a while. I already tried:

This is my xml code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gmap"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class = "com.google.android.gms.maps.MapFragment"
    />
</LinearLayout>

And this is my main activity

    [Activity(Label = "@string/app_name", MainLauncher = true)]
    public class MainActivity : AppCompatActivity, IOnMapReadyCallback
    {
 protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.gmap);
            mapFragment.GetMapAsync(this);
        }
        public void OnMapReady(GoogleMap map)
        {
            // Do something with the map, i.e. add markers, move to a specific location, etc.
            // Set up a normal map
            map.MapType = GoogleMap.MapTypeHybrid;
            // Map settings
            map.UiSettings.ZoomControlsEnabled = true;
            map.UiSettings.CompassEnabled = true;
        }
    }
}

4 Answers 4

1

use android:name = "" instead of class tag

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

     <fragment 
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/gmap"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name = "com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
Sign up to request clarification or add additional context in comments.

1 Comment

I had the android:name property before, the same error show up. Thanks for the reply
1

please test it

<?xml version="1.0" encoding="utf-8"?>
<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.MapFragment" />

3 Comments

The error just changed: Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class fragment'. Thank you for your reply!!
Hello, not yet. The error mssg just changed that is all.
Can you send the code to my email? [email protected]
1

Try to use :

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/map"
  class="com.google.android.gms.maps.SupportMapFragment"/>

then in your activity call :

SupportMapFragment _mapFragment = SupportFragmentManager.FindFragmentById(Resource.Id.map).JavaCast<SupportMapFragment>();         
_mapFragment.GetMapAsync(this);

Comments

0

I ended up asking for help in the Xamarin Forums, the fix was in the android manifest where the meta-data needs to be wrapped in a application tag. I also updated the code to use the SupportFragmentManager class like so:

var mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.gmap);  
            mapFragment.GetMapAsync(this);

And the android layout with the updated fragment

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/gmap"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          class="com.google.android.gms.maps.SupportMapFragment"/>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.