Google MapView V3不会加载磁贴

时间:2016-12-01 19:16:26

标签: android android-fragments android-mapview android-maps-v2

我想获取片段里面的地图我已经从mapfragment迁移到mapview。

在mapfragment模式中,地图在简单活动中运行良好。但是当我在mappager中的一个片段中放置一个mapview时。地图视图仍然是灰色的。

我不知道为什么。

我的MapViewFragment代码:

public class MapViewFragment extends RecordFragment implements GoogleMap.OnMarkerClickListener,OnMapReadyCallback {
    private GoogleMap mMap;
    private MapView mapView;


    public MapViewFragment() {
        // Required empty public constructor
    }

    public static MapViewFragment newInstance() {
        MapViewFragment fragment = new MapViewFragment();
        // Supply index input as an argument.
        Bundle args = new Bundle();

        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_map, container, false);
        // Gets the MapView from the XML layout and creates it
        mapView = (MapView) view.findViewById(R.id.mapView);
        mapView.onCreate(savedInstanceState);

        // Gets to GoogleMap from the MapView and does initialization stuff
        mapView.getMapAsync(this);

        return view;

    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setOnMarkerClickListener(this);
        UiSettings settings = mMap.getUiSettings();
        settings.setCompassEnabled(true);
        try{
            if (PermissionsHelper.checkPermissionLocation(getActivity())) {
                mMap.setMyLocationEnabled(true);
            }
        }catch (SecurityException e){
            e.printStackTrace();
        }

        MapsInitializer.initialize(this.getActivity());


    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        return false;
    }
}

fragment_map.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>

我的manifest.xml:

 <permission
        android:name="com.kwik.googlemapsv2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.kwik.googlemapsv2.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AI..." />

结果: enter image description here

LogCat:

12-01 20:33:26.981 11205-11205/com.kwik D/RelationGraph: garbageCollect()
12-01 20:33:27.091 11205-11205/com.kwik D/RelationGraph: garbageCollect()
12-01 20:33:27.171 11205-11205/com.kwik W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000008/n/armeabi-v7a
12-01 20:33:27.171 11205-11205/com.kwik W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000008/n/armeabi
12-01 20:33:27.181 11205-11205/com.kwik D/ResourcesManager: For user 0 new overlays fetched Null
12-01 20:33:27.221 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.241 11205-11205/com.kwik I/Google Maps Android API: Google Play services client version: 9452000
12-01 20:33:27.261 11205-11205/com.kwik I/Google Maps Android API: Google Play services package version: 10084438
12-01 20:33:27.271 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.291 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.301 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.321 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.341 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.351 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.361 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.381 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.381 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskWriteViolation
12-01 20:33:27.401 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.451 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.451 11205-11205/com.kwik I/c: Token loaded from file. Expires in: 428631454 ms.
12-01 20:33:27.451 11205-11205/com.kwik I/c: Scheduling next attempt in 428331 seconds.
12-01 20:33:27.491 11205-11205/com.kwik D/AbsListView: Get MotionRecognitionManager
12-01 20:33:27.501 11205-11205/com.kwik E/MotionRecognitionManager: mSContextService = android.hardware.scontext.ISContextService$Stub$Proxy@22eb3b9
12-01 20:33:27.501 11205-11205/com.kwik E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@2bb13fe
12-01 20:33:27.501 11205-11205/com.kwik E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@2bb13fe
12-01 20:33:27.541 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskWriteViolation
12-01 20:33:27.541 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskWriteViolation
12-01 20:33:27.551 11205-11205/com.kwik W/System.err: mkdir failed: EEXIST (File exists) : /storage/emulated/0/Android/data/com.kwik/cache/debug
12-01 20:33:27.551 11205-11205/com.kwik W/System.err: mkdir failed: EEXIST (File exists) : /storage/emulated/0/Android/data/com.kwik/cache
12-01 20:33:27.571 11205-11277/com.kwik I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-01 20:33:27.571 11205-11277/com.kwik I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-01 20:33:27.641 11205-11315/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.641 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:27.641 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskWriteViolation
12-01 20:33:27.711 11205-11268/com.kwik D/libEGL: loaded /vendor/lib/egl/libGLES_mali.so
12-01 20:33:27.731 11205-11268/com.kwik D/libEGL: eglInitialize EGLDisplay = 0xdfb5a7c4
12-01 20:33:27.731 11205-11268/com.kwik I/OpenGLRenderer: Initialized EGL, version 1.4
12-01 20:33:27.741 11205-11268/com.kwik D/mali_winsys: new_window_surface returns 0x3000,  [1080x1920]-format:1
12-01 20:33:27.771 11205-11277/com.kwik I/qtaguid: Tagging socket 57 with tag 3000110100000000{805310721,0} uid -1, pid: 11205, getuid(): 10237
12-01 20:33:27.831 11205-11205/com.kwik I/Choreographer: Skipped 57 frames!  The application may be doing too much work on its main thread.
12-01 20:33:27.841 11205-11314/com.kwik D/libEGL: eglInitialize EGLDisplay = 0xd637f514
12-01 20:33:27.841 11205-11314/com.kwik D/mali_winsys: new_window_surface returns 0x3000,  [1080x1185]-format:2
12-01 20:33:27.851 11205-11268/com.kwik D/libGLESv1: DTS_GLAPI : DTS is not allowed for Package : com.kwik
12-01 20:33:28.021 11205-11277/com.kwik I/qtaguid: Tagging socket 74 with tag 3000110100000000{805310721,0} uid -1, pid: 11205, getuid(): 10237
12-01 20:33:28.061 11205-11205/com.kwik D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
12-01 20:33:28.141 11205-11268/com.kwik D/libEGL: eglInitialize EGLDisplay = 0xdfb5a614
12-01 20:33:28.141 11205-11205/com.kwik I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@805ab08 time:664641245
12-01 20:33:28.171 11205-11277/com.kwik I/qtaguid: Untagging socket 57
12-01 20:33:28.181 11205-11345/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:28.181 11205-11278/com.kwik I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-01 20:33:28.181 11205-11278/com.kwik I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
12-01 20:33:28.181 11205-11278/com.kwik I/qtaguid: Tagging socket 57 with tag 3000110100000000{805310721,0} uid -1, pid: 11205, getuid(): 10237
12-01 20:33:28.261 11205-11278/com.kwik I/qtaguid: Untagging socket 57
12-01 20:33:28.261 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskReadViolation
12-01 20:33:28.261 11205-11205/com.kwik W/f: Suppressed StrictMode policy violation: StrictModeDiskWriteViolation
12-01 20:33:29.651 11205-11316/com.kwik W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
12-01 20:33:29.671 11205-11316/com.kwik I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:2
12-01 20:33:29.671 11205-11316/com.kwik I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 2
12-01 20:33:29.671 11205-11316/com.kwik E/DynamiteModule: Failed to load DynamiteLoader: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.dynamite.DynamiteModule$DynamiteLoaderClassLoader" on path: DexPathList[[zip file "/data/app/com.kwik-1/base.apk"],nativeLibraryDirectories=[/data/app/com.kwik-1/lib/arm, /vendor/lib, /system/lib]]
12-01 20:33:29.671 11205-11316/com.kwik W/DynamiteModule: Failed to load remote module: Failed to get module context
12-01 20:33:29.671 11205-11316/com.kwik W/DynamiteModule: Failed to load module via fast routetn: Remote load failed. No local fallback found.
12-01 20:33:29.681 11205-11316/com.kwik W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
12-01 20:33:29.681 11205-11316/com.kwik D/RelationGraph: garbageCollect()
12-01 20:33:29.681 11205-11316/com.kwik D/RelationGraph: garbageCollect()
12-01 20:33:29.681 11205-11316/com.kwik I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:2
12-01 20:33:29.681 11205-11316/com.kwik I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 2
12-01 20:33:29.691 11205-11316/com.kwik D/RelationGraph: garbageCollect()
12-01 20:33:29.701 11205-11316/com.kwik W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/00000007/n/armeabi
12-01 20:33:29.721 11205-11316/com.kwik D/ResourcesManager: For user 0 new overlays fetched Null

1 个答案:

答案 0 :(得分:1)

我自己发现,地图非常慢,为了解决这个问题,我需要为地图视图生命周期声明所有方法!

Google doc:Google Maps V3

  

在完全交互模式下使用API​​时,MapView的用户   class必须将以下活动生命周期方法转发给   MapView类中的相应方法:onCreate(),onStart(),   onResume(),onPause(),onStop(),onDestroy(),onSaveInstanceState(),   和onLowMemory()。 GitHub上的ApiDemos存储库包含一个示例   这演示了如何转发活动生命周期方法。什么时候   在lite模式下使用API​​,转发生命周期事件是可选的。   有关详细信息,请参阅lite模式文档。

我在MapViewFragment上添加了这个:

 @Override
    public void onResume() {
        mapView.onResume();
        super.onResume();
    }

    @Override
    public void onPause() {
        mapView.onPause();
        super.onPause();
    }

    @Override
    public void onDestroy() {
        mapView.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onLowMemory() {
        mapView.onLowMemory();
        super.onLowMemory();
    }