本文介绍了这里的Maps MapView在Fragment中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在片段中实现此处地图,但是它不起作用.我出了很多车祸

I am trying to implement Here Maps in Fragment but it does not work. I got lots of crashes

崩溃日志:

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
        Suppressed: java.lang.Throwable: HERE SDK Version: 3.7.0.118
        at com.nokia.maps.MapsEngine$l.uncaughtException(MapsEngine.java:378)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
        Suppressed: java.lang.Throwable: HERE SDK Version: 3.7.0.118
        at com.nokia.maps.MapsEngine$l.uncaughtException(MapsEngine.java:378)
        at com.nokia.maps.MapsEngine$l.uncaughtException(MapsEngine.java:379)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
     Caused by: com.here.android.mpa.common.UnintializedMapEngineException: Cannot create HERE SDK object before MapEngine is initialized. See MapEngine.init()
        at com.nokia.maps.BaseNativeObject.u(BaseNativeObject.java:39)
        at com.nokia.maps.BaseNativeObject.<init>(BaseNativeObject.java:26)
        at com.nokia.maps.MapImpl.<init>(MapImpl.java:424)
        at com.here.android.mpa.mapping.Map.<init>(Map.java:710)
        at ie.globetech.transitconnex.activity.bustrips.BusTripFragment.onEngineInitializationCompleted(BusTripFragment.java:179)
        at com.here.android.mpa.common.MapEngine.init(MapEngine.java:279)
        at ie.globetech.transitconnex.activity.bustrips.BusTripFragment.onCreate(BusTripFragment.java:136)
        at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
        at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1188)
        at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1071)
        at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:115)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3248)
        at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3200)
        at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:195)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:597)
        at ie.globetech.transitconnex.activity.bustrips.BusTripMainActivity.onStart(BusTripMainActivity.java:125)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1256)
        at android.app.Activity.performStart(Activity.java:6965)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2934)
            ... 9 more

片段布局:

<com.here.android.mpa.mapping.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true" />

片段类:

    public class BusTripFragment extends Fragment{

           private Activity mActivity;
           private Map map = null;
           private MapView mapView;

             @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    ApplicationContext appContext = new ApplicationContext(mActivity.getApplicationContext());
                    MapEngine.getInstance().init(appContext, this);

              }

 @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mActivity = (Activity) activity;
            //mCallbacks = (MyNavigationDrawerCallbacks) activity;
        } catch (ClassCastException e) {}
    }


        @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                View view = inflater.inflate(R.layout.trip_fragment, container, false);
               mapView = (MapView) view.findViewById(R.id.map);
               return view;      
                }

    @Override
        public void onEngineInitializationCompleted(Error error) {

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

            isMapEngineInitialized = true;

            if (map == null) {
                map = new Map();
            }

            mapView.setMap(map);

            // Set the map center to the Vancouver region (no animation)
            map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0), Map.Animation.NONE);

            // Set the zoom level to the average between min and max
            map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
        }

     }

我正在使用HERE SDK版本:3.7.0.118

I am using HERE SDK Version: 3.7.0.118

我想穿过therads

I want through below therads

  1. HERE Map/MapView,而无需使用MapFragment

任何人都知道如何处理Fragment中的Here Maps MapView吗?

Any one has any idea how to deal with Here Maps MapView in Fragment ?

推荐答案

我自己的解决方案,效果很好.完全删除了 MapView

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

只需在片段

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

现在,在 onCreateView(...)中动态创建 MapFragment ,并添加到 FrameLayout 和初始化

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

    MapFragment mapFragment = new MapFragment();
    FragmentManager fm = mActivity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.simpleFrameLayout, mapFragment).commit();

    mapFragment.init(mActivity, new OnEngineInitListener() {
                @Override
                public void onEngineInitializationCompleted(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());
                    }
                }
            });

这篇关于这里的Maps MapView在Fragment中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 01:54