gpt4 book ai didi

android - 这里的 Maps MapView 在 Fragment 中不起作用

转载 作者:太空狗 更新时间:2023-10-29 13:48:27 25 4
gpt4 key购买 nike

我正在尝试在 Fragment 中实现 Here Maps 但它不起作用。我遇到了很多崩溃

崩溃日志:

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

fragment 布局:

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

fragment 类:

    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

我想通过下面的命令

  1. HERE Map/MapView without using MapFragment

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

最佳答案

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

刚刚在 Fragment 的布局 xml 中添加了 FrameLayout

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

现在,在onCreateView(...)中动态创建了MapFragment并添加到FrameLayout和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());
}
}
});

关于android - 这里的 Maps MapView 在 Fragment 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50523613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com