MapFragment在onMapReady之后没有更新

时间:2018-02-27 09:47:48

标签: android google-maps-android-api-2

为Android API 23及更高版本构建: 我试图用一个Activity生成一个应用程序,它使用片段事务在两个片段之间切换:

public class ControlActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_control);

    Fragment fragment = StationMapFragment.newInstance();

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.androidControl_frameLayout_content, fragment);

    fragmentTransaction.commit();

    }
}

我在主要活动中使用FrameLayout支持此功能:

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/androidControl_frameLayout_content">

    </FrameLayout>

然后我在一个新类中扩展了MapFragment(我希望这可以让我避免嵌套片段并保持我的ControlActivity类相对干净:

public class StationMapFragment extends MapFragment implements OnMapReadyCallback {

    private GoogleMap mGoogleMap;

    Marker userPosition;

    LatLng userDefinedLocation;

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {

        super.onCreateView(layoutInflater, container, savedInstanceState);

        View layout = layoutInflater.inflate(R.layout.fragment_station_map, container, false);

        getMapAsync(this);

        return layout;

    }

    @Override
    public void onMapReady(GoogleMap googleMap) {

        Log.wtf("OnMapReady", "Start");

        mGoogleMap = googleMap;

        Log.wtf("OnMapReady", mGoogleMap.getCameraPosition().toString());

        mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(54.75046079289966, -4.245360866189002)));
        mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(5), 2000, null);

        Log.wtf("OnMapReady", googleMap.getCameraPosition().toString());

        mGoogleMap.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {
            @Override
            public void onCameraMove() {
                Log.wtf("CameraMove", mGoogleMap.getCameraPosition().toString());
            }
        });

    }
}

当我启动应用程序时,我没有看到logcat中的任何错误(包括在下面),并且我的地图已加载。但是我的onMapReady方法似乎永远不会被触发。

02-27 09:46:15.910 5287-5287/? E/Zygote: v2
02-27 09:46:15.910 5287-5287/? I/libpersona: KNOX_SDCARD checking this for 10290
02-27 09:46:15.910 5287-5287/? I/libpersona: KNOX_SDCARD not a persona
02-27 09:46:15.914 5287-5287/? E/Zygote: accessInfo : 0
02-27 09:46:15.916 5287-5287/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2],  Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.0_0009, [-1 -1 -4 -1 0 1]
02-27 09:46:15.920 5287-5287/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.example.nicsutherland.stationfinder 
02-27 09:46:15.930 5287-5287/? I/art: Late-enabling -Xcheck:jni
02-27 09:46:15.964 5287-5287/? D/TimaKeyStoreProvider: TimaKeyStore is not enabled: cannot add TimaSignature Service and generateKeyPair Service
02-27 09:46:16.010 5287-5287/com.example.nicsutherland.stationfinder W/ActivityThread: Application com.example.nicsutherland.stationfinder is waiting for the debugger on port 8100...
02-27 09:46:16.011 5287-5287/com.example.nicsutherland.stationfinder I/System.out: Sending WAIT chunk
02-27 09:46:17.103 5287-5294/com.example.nicsutherland.stationfinder I/art: Debugger is active
02-27 09:46:17.214 5287-5287/com.example.nicsutherland.stationfinder I/System.out: Debugger has connected
02-27 09:46:17.214 5287-5287/com.example.nicsutherland.stationfinder I/System.out: waiting for debugger to settle...
02-27 09:46:17.415 5287-5287/com.example.nicsutherland.stationfinder I/System.out: waiting for debugger to settle...
02-27 09:46:17.616 5287-5287/com.example.nicsutherland.stationfinder I/System.out: waiting for debugger to settle...
02-27 09:46:17.817 5287-5287/com.example.nicsutherland.stationfinder I/System.out: waiting for debugger to settle...
02-27 09:46:18.018 5287-5287/com.example.nicsutherland.stationfinder I/System.out: waiting for debugger to settle...
02-27 09:46:18.220 5287-5287/com.example.nicsutherland.stationfinder I/System.out: waiting for debugger to settle...
02-27 09:46:18.421 5287-5287/com.example.nicsutherland.stationfinder I/System.out: waiting for debugger to settle...
02-27 09:46:18.622 5287-5287/com.example.nicsutherland.stationfinder I/System.out: debugger has settled (1418)
02-27 09:46:18.988 5287-5287/com.example.nicsutherland.stationfinder W/System: ClassLoader referenced unknown path: /data/app/com.example.nicsutherland.stationfinder-2/lib/arm
02-27 09:46:19.034 5287-5287/com.example.nicsutherland.stationfinder I/InstantRun: starting instant run server: is main process
02-27 09:46:19.171 5287-5287/com.example.nicsutherland.stationfinder W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-27 09:46:19.363 5287-5287/com.example.nicsutherland.stationfinder D/TextView: setTypeface with style : 0
02-27 09:46:19.365 5287-5287/com.example.nicsutherland.stationfinder D/TextView: setTypeface with style : 0
02-27 09:46:19.375 5287-5287/com.example.nicsutherland.stationfinder D/TextView: setTypeface with style : 0
02-27 09:46:19.424 5287-5287/com.example.nicsutherland.stationfinder D/TextView: setTypeface with style : 0
02-27 09:46:19.448 5287-5287/com.example.nicsutherland.stationfinder D/TextView: setTypeface with style : 0
02-27 09:46:19.455 5287-5287/com.example.nicsutherland.stationfinder D/TextView: setTypeface with style : 0
02-27 09:46:19.463 5287-5287/com.example.nicsutherland.stationfinder D/TextView: setTypeface with style : 0
02-27 09:46:19.538 5287-5287/com.example.nicsutherland.stationfinder I/zzbz: Making Creator dynamically
02-27 09:46:19.560 5287-5287/com.example.nicsutherland.stationfinder I/DynamiteModule: Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:18
02-27 09:46:19.560 5287-5287/com.example.nicsutherland.stationfinder I/DynamiteModule: Selected remote version of com.google.android.gms.maps_dynamite, version >= 18
02-27 09:46:19.579 5287-5287/com.example.nicsutherland.stationfinder W/System: ClassLoader referenced unknown path: 
02-27 09:46:19.622 5287-5287/com.example.nicsutherland.stationfinder W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000033/n/armeabi
02-27 09:46:19.715 5287-5287/com.example.nicsutherland.stationfinder I/Google Maps Android API: Google Play services client version: 11910000
02-27 09:46:19.727 5287-5287/com.example.nicsutherland.stationfinder I/Google Maps Android API: Google Play services package version: 11975438
02-27 09:46:20.297 5287-5292/com.example.nicsutherland.stationfinder I/art: Do partial code cache collection, code=23KB, data=30KB
02-27 09:46:20.298 5287-5292/com.example.nicsutherland.stationfinder I/art: After code cache collection, code=22KB, data=30KB
02-27 09:46:20.298 5287-5292/com.example.nicsutherland.stationfinder I/art: Increasing code cache capacity to 128KB
02-27 09:46:20.512 5287-5287/com.example.nicsutherland.stationfinder D/AbsListView: Get MotionRecognitionManager
02-27 09:46:20.520 5287-5287/com.example.nicsutherland.stationfinder D/MotionRecognitionManager: mSContextService = com.samsung.android.hardware.context.ISemContextService$Stub$Proxy@e01811a
02-27 09:46:20.524 5287-5287/com.example.nicsutherland.stationfinder D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@62694e6
02-27 09:46:20.525 5287-5287/com.example.nicsutherland.stationfinder D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@62694e6
02-27 09:46:20.715 5287-5321/com.example.nicsutherland.stationfinder D/NetworkSecurityConfig: No Network Security Config specified, using platform default
02-27 09:46:20.729 5287-5321/com.example.nicsutherland.stationfinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-27 09:46:20.730 5287-5321/com.example.nicsutherland.stationfinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-27 09:46:20.818 5287-5287/com.example.nicsutherland.stationfinder D/Choreographer: init sf_choreo_doframe   debug_Level : 0x4f4cdebug_game_running : false
02-27 09:46:20.831 5287-5287/com.example.nicsutherland.stationfinder D/ViewRootImpl@e7c8f95[ControlActivity]: ThreadedRenderer.create() translucent=false
02-27 09:46:20.836 5287-5287/com.example.nicsutherland.stationfinder D/InputTransport: Input channel constructed: fd=102
02-27 09:46:20.837 5287-5287/com.example.nicsutherland.stationfinder D/ViewRootImpl@e7c8f95[ControlActivity]: setView = DecorView@99c9c9b[ControlActivity] touchMode=true
02-27 09:46:20.910 5287-5287/com.example.nicsutherland.stationfinder D/ViewRootImpl@e7c8f95[ControlActivity]: dispatchAttachedToWindow
02-27 09:46:20.930 5287-5292/com.example.nicsutherland.stationfinder I/art: Do partial code cache collection, code=49KB, data=62KB
02-27 09:46:20.930 5287-5292/com.example.nicsutherland.stationfinder I/art: After code cache collection, code=49KB, data=62KB
02-27 09:46:20.930 5287-5292/com.example.nicsutherland.stationfinder I/art: Increasing code cache capacity to 256KB
02-27 09:46:20.931 5287-5287/com.example.nicsutherland.stationfinder D/ViewRootImpl@e7c8f95[ControlActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][1080,1920] result=0x27 surface={isValid=true -642435072} surfaceGenerationChanged=true
02-27 09:46:20.933 5287-5287/com.example.nicsutherland.stationfinder D/ViewRootImpl@e7c8f95[ControlActivity]: mHardwareRenderer.initialize() mSurface={isValid=true -642435072} hwInitialized=true
02-27 09:46:20.983 5287-5350/com.example.nicsutherland.stationfinder D/libEGL: loaded /vendor/lib/egl/libGLES_mali.so
02-27 09:46:20.987 5287-5287/com.example.nicsutherland.stationfinder W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
02-27 09:46:21.093 5287-5350/com.example.nicsutherland.stationfinder I/OpenGLRenderer: Initialized EGL, version 1.4
02-27 09:46:21.093 5287-5350/com.example.nicsutherland.stationfinder D/OpenGLRenderer: Swap behavior 1
02-27 09:46:21.100 5287-5350/com.example.nicsutherland.stationfinder D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000,  [1080x1920]-format:1
02-27 09:46:21.177 5287-5287/com.example.nicsutherland.stationfinder D/ViewRootImpl@e7c8f95[ControlActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1080, 1920) ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
02-27 09:46:21.455 5287-5322/com.example.nicsutherland.stationfinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-27 09:46:21.456 5287-5322/com.example.nicsutherland.stationfinder I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
02-27 09:46:22.818 5287-5348/com.example.nicsutherland.stationfinder W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
02-27 09:46:22.840 5287-5348/com.example.nicsutherland.stationfinder I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
02-27 09:46:22.841 5287-5348/com.example.nicsutherland.stationfinder I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4
02-27 09:46:22.871 5287-5348/com.example.nicsutherland.stationfinder W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000031/n/armeabi-v7a
02-27 09:46:22.871 5287-5348/com.example.nicsutherland.stationfinder W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000031/n/armeabi

0 个答案:

没有答案