question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google maps fragment in epoxy view

See original GitHub issue

I’m currently exploring the new MvRx stack from Airbnb

Rigth now i am adding a google maps fragment successfully to a BaseMvRxFragment in a BottomNavigationView.

The problem is that the 2. time i navigate to the MapFragment my app crashes and i get the following error message:

    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: getflareapp.com.s2s, PID: 19184
        android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment
        Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
        Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f080093, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
            at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3752)
            at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
            at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
            at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
            at android.view.View.inflate(View.java:23239)
            at getflareapp.com.s2s.views.MapView.<init>(MapView.kt:19)
            at getflareapp.com.s2s.views.MapView.<init>(MapView.kt:14)
            at getflareapp.com.s2s.views.MapView.<init>(Unknown Source:6)
            at getflareapp.com.s2s.views.MapViewModel_.buildView(MapViewModel_.java:42)
            at getflareapp.com.s2s.views.MapViewModel_.buildView(MapViewModel_.java:22)

MapFragment.kt

    /**
     * A simple [BaseFragment] subclass.
     *
     */
    class MapFragment : BaseFragment() {
    
    
        private val mViewModel: ChatViewModel by fragmentViewModel()
    
        override fun epoxyController() = simpleController(mViewModel) {state ->
    
    
            mapView{
                id("map")
            }
        }
    }

MapView.kt

 @ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_MATCH_HEIGHT)
    class MapView @JvmOverloads constructor(
            context: Context,
            attrs: AttributeSet? = null,
            defStyleAttr: Int = 0
    ) : FrameLayout(context, attrs, defStyleAttr) {
    
        init {
            // TODO: Fix crash on second view.
            inflate(context, R.layout.view_map, this)
        }
    }

view_map.xml

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout 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">
    
        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map2"
            android:name="getflareapp.com.s2s.ui.map.MapFragment"
            class="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".ui.MainActivity" />
    
    </FrameLayout>

Thanks for any help! ❤️

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
dmnugent80commented, Mar 21, 2019

If anybody is wondering, using a MapView in lite mode works just fine in an Epoxy view.

Just put a MapView in a layout xml file:

    <com.google.android.gms.maps.MapView
            android:id="@+id/my_location_map"
            android:layout_width="match_parent"
            android:layout_height="220dp"
            app:cameraZoom="15"
            app:liteMode="true"/>

Then the view (in Kotlin), MyMapView.kt:

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
class MyMapView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private var marker: Marker? = null
    private var myLocation: LatLng? = null
    private val markerOptions = MarkerOptions()
    private var googleMap: GoogleMap? = null

    init {
        View.inflate(context, R.layout.my_map_view_layout, this)
        my_location_map.isClickable = false
        my_location_map.isLongClickable = false
    }

    fun startMap() {
        my_location_map.onCreate(null)
        my_location_map.getMapAsync {
            googleMap = it
            googleMap?.uiSettings?.isMapToolbarEnabled = false
            myLocation?.let {
                googleMap?.moveCamera(CameraUpdateFactory.newLatLng(it))
                markerOptions.position(it)
                marker?.remove()
                marker = googleMap?.addMarker(markerOptions)
            }
        }
    }

    @ModelProp
    fun setLocation(newLocation: LatLng?) =
        newLocation?.let {
            myLocation = it
            startMap()
        }
}

Then in the Epoxy controller:

    private fun renderLoadedState(data: MyState) {

        /**
         *  [MyMapView]
         *  data.myLocation is a LatLng
         */
        myMapView {
            id("my_map_view")
            location(data.myLocation)
        }

       //.................

Note that if you use a MapView in regular mode (not litemode) you’ll need to route all of the Activity lifecycle events down to the MapView as well.

0reactions
idrisadetunmbicommented, Jan 24, 2020

@dmnugent80, how does one route the MapView in a regular mode considering a property of it is required in the activity/fragment class and epoxy is not structured to allow for that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google maps fragment in epoxy view - android - Stack Overflow
I´ve problems adding directly the map fragment inner other fragment, so i suggest change that with Framelayout and inflate the fragment ...
Read more >
[Solved]-Google maps fragment in epoxy view-kotlin
I´ve problems adding directly the map fragment inner other fragment, so i suggest change that with Framelayout and inflate the fragment manually.
Read more >
How to Implement Google Map Inside Fragment in Android ...
Google Map Tutorial : In This Video, You Will Learn How to Integrate Google Map Inside Fragment in Android Studio.Build.
Read more >
How to Implement Google Map Inside Fragment in Android?
Go to website site https://mapsplatform.google.com. The interface shown below will appear. Click on Create Project. Give your project a suitable ...
Read more >
Snapping behaviour in Epoxy Carousel and its pitfalls
During the development of one of our apps, we were tasked to develop a carousel view connected to a Google map in such...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found