I'm getting the following error during my mapView.getMapAsync{}
call:
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)
Here is my code:
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()
}
}
}
Unfortunately I don't understand the error message Calling getSourceAs when a newer style is loading/has loaded.
This is the initial load of the map style so I'm not sure why it's telling me I'm trying to change the style.
What does the error mean and how can I fix it?