Skip to content Skip to sidebar Skip to footer

Here Maps Mapview Does Not Work In Fragment

I am trying to implement Here Maps in Fragment but it does not work. I got lots of crashes Crash Logs: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java

Solution 1:

My own solution and it worked very well. Removed MapView completely

Just added FrameLayout in layout xml of Fragment

 <FrameLayout
        android:id="@+id/simpleFrameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true" /> 

Now, in onCreateView(...) created MapFragment dynamically and added in FrameLayout and init

MapFragmentmapFragment=newMapFragment();
    FragmentManagerfm= mActivity.getFragmentManager();
    FragmentTransactionft= fm.beginTransaction();
    ft.replace(R.id.simpleFrameLayout, mapFragment).commit();

    mapFragment.init(mActivity, newOnEngineInitListener() {
                @OverridepublicvoidonEngineInitializationCompleted(OnEngineInitListener.Error error) {
                    if (error == OnEngineInitListener.Error.NONE) {

                        // retrieve a reference of the map from the map fragment
                        map = mapFragment.getMap();
                    } else {
                        logger.error("ERROR: Cannot initialize Map Fragment: " + error.getStackTrace());
                    }
                }
            });

Solution 2:

According to the stack trace: Caused by: com.here.android.mpa.common.UnintializedMapEngineException: Cannot create HERE SDK object before MapEngine is initialized. See MapEngine.init()

And from your source code: public void onEngineInitializationCompleted(Error error) {

// retrieve a reference of the map from the map fragment//map = mapFragment.getMap();

        isMapEngineInitialized = true;

... }

You are not checking for the error return code within onEngineInitializationCompleted.

The call stack you are seeing implies an error returned from the engine setup. Please print the error and we can find the proper solution.

Post a Comment for "Here Maps Mapview Does Not Work In Fragment"