android - Mapbox IllegalStateException : Calling getSourceAs when a newer style is loading/has loaded

标签 android kotlin mapbox mapbox-android

我在 mapView.getMapAsync{} 期间收到以下错误称呼:

2019-10-03 19:37:57.605 10964-10964/my.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: my.app, PID: 10964
    java.lang.IllegalStateException: Calling getSourceAs when a newer style is loading/has loaded.
        at com.mapbox.mapboxsdk.maps.Style.validateState(Style.java:584)
        at com.mapbox.mapboxsdk.maps.Style.getSourceAs(Style.java:131)
        at com.mapbox.mapboxsdk.location.LocationLayerController.refreshSource(LocationLayerController.java:292)
        at com.mapbox.mapboxsdk.location.LocationLayerController.setLocationPoint(LocationLayerController.java:302)
        at com.mapbox.mapboxsdk.location.LocationLayerController.access$000(LocationLayerController.java:61)
        at com.mapbox.mapboxsdk.location.LocationLayerController$1.onNewAnimationValue(LocationLayerController.java:422)
        at com.mapbox.mapboxsdk.location.LocationLayerController$1.onNewAnimationValue(LocationLayerController.java:418)
        at com.mapbox.mapboxsdk.location.MapboxAnimator.postUpdates(MapboxAnimator.java:83)
        at com.mapbox.mapboxsdk.location.MapboxAnimator.onAnimationUpdate(MapboxAnimator.java:71)
        at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1547)
        at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
        at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
        at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)
        at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)
        at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)
        at android.animation.AnimatorSet.start(AnimatorSet.java:729)
        at android.animation.AnimatorSet.start(AnimatorSet.java:684)
        at com.mapbox.mapboxsdk.location.MapboxAnimatorSetProvider.startAnimation(MapboxAnimatorSetProvider.java:30)
        at com.mapbox.mapboxsdk.location.LocationAnimatorCoordinator.playAnimators(LocationAnimatorCoordinator.java:294)
        at com.mapbox.mapboxsdk.location.LocationAnimatorCoordinator.feedNewLocation(LocationAnimatorCoordinator.java:97)
        at com.mapbox.mapboxsdk.location.LocationComponent.updateLocation(LocationComponent.java:1317)
        at com.mapbox.mapboxsdk.location.LocationComponent.access$1000(LocationComponent.java:94)
        at com.mapbox.mapboxsdk.location.LocationComponent$CurrentLocationEngineCallback.onSuccess(LocationComponent.java:1473)
        at com.mapbox.mapboxsdk.location.LocationComponent$CurrentLocationEngineCallback.onSuccess(LocationComponent.java:1461)
        at com.mapbox.android.core.location.GoogleLocationEngineImpl$GoogleLocationEngineCallbackTransport.onLocationResult(GoogleLocationEngineImpl.java:114)
        at com.google.android.gms.internal.location.zzau.notifyListener(Unknown Source:4)
        at com.google.android.gms.common.api.internal.ListenerHolder.notifyListenerInternal(Unknown Source:17)
        at com.google.android.gms.common.api.internal.ListenerHolder$zaa.handleMessage(Unknown Source:5)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at com.google.android.gms.internal.base.zap.dispatchMessage(Unknown Source:8)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6702)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

这是我的代码:

MapFragment.kt
var symbolOptions = SymbolOptions()
private var symbolManager: SymbolManager? = null
private var mapView: MapView? = null
private lateinit var mapboxMap: MapboxMap
private var navigationMapRoute: NavigationMapRoute? = null

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    /** Initialise Mapbox **/
    mapView = view.findViewById(R.id.mapView)
    mapView?.onCreate(savedInstanceState)
    val destinationMarker = ContextCompat.getDrawable(activity, R.drawable.logo) ?: return
    mapView?.getMapAsync { mapboxMap ->
        Log.d("getMapAsync") // this doesn't print 
        this.mapboxMap = mapboxMap
        this.mapboxMap.setStyle(Style.MAPBOX_STREETS) { style ->
            style.addImage("destination", destinationMarker)
            showUserLocation(style)
            resetCamera()
        }
    }
}

不幸的是,我不明白错误消息 Calling getSourceAs when a newer style is loading/has loaded.这是 map 样式的初始加载,所以我不确定为什么它告诉我我正在尝试更改样式。

错误是什么意思,我该如何解决?

最佳答案

只需使用:

 mapboxMap.getStyle(new Style.OnStyleLoaded() {
            @Override
            public void onStyleLoaded(@NonNull Style style) {
                // Continue your job here

            }
        });

关于android - Mapbox IllegalStateException : Calling getSourceAs when a newer style is loading/has loaded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58217011/

相关文章:

kotlin - 使用 SearchView 过滤 RecyclerView/ListAdapter

javascript - 为什么 map 框标记不能与外部数据 (CSV) 文件正确设置样式

android - Mapbox 'setMyLocationEnabled' 不工作

Mapbox GL JS : Add layer below US state labels?

android - 如何在 Camera2 API 中启用前置摄像头?

android - 如何在不将 App Theme 更改为 Custom Theme 的情况下制作自定义标题栏?

android - 运行非离线语言时的 SpeechRecognizer ERROR_SERVER

android - WebView 和软键盘问题

java - 检查/存储来自 EditTexts 的输入(Android/Java)

java - Kotlin 中的一切都是对象吗?