I have an activity which holds multiple addresses (Street, City, Country, Postcode) and displays them to the user. Under each address, I want to display a MapFragment
, passing in the address information and display the point to the user on the map.
When I tried it, the app crashed and I got the below error. It points me to where I inflate the parent layout which holds all address instances.
Caused by: java.lang.IllegalArgumentException: Binary XML file line #45: Duplicate id 0x7f0a0211, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
Is there a way to workaround this error and/or display multiple MapFragments
otherwise?
Edit: I want my layout to look something like this. I can show multiple text entries, but once I try to add 2 mapFragments, I get a crash.
XML code:
<fragment
android:id="@+id/map1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@id/contact_address_info"
android:layout_toEndOf="@id/contact_address_image"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:fitsSystemWindows="true"
android:name="com.google.android.gms.maps.SupportMapFragment" />
<fragment
android:id="@+id/map2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@id/contact_address_info"
android:layout_toEndOf="@id/contact_address_image"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:fitsSystemWindows="true"
android:name="com.google.android.gms.maps.SupportMapFragment" />
<fragment
android:id="@+id/map3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@id/contact_address_info"
android:layout_toEndOf="@id/contact_address_image"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:fitsSystemWindows="true"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Java code:
SupportMapFragment mapFragment1;
mapFragment1 = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map1);
if (mapFragment1 != null) mapFragment1.getMapAsync(this);
SupportMapFragment mapFragment2;
mapFragment2 = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map2);
if (mapFragment2 != null) mapFragment2.getMapAsync(this);
SupportMapFragment mapFragment3;
mapFragment3 = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map3);
if (mapFragment3 != null) mapFragment3.getMapAsync(this);
User contributions licensed under CC BY-SA 3.0