Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Map error when animating using LatLngBounds #11577

Closed
tan-tran-viet-xx opened this issue Mar 31, 2018 · 1 comment
Closed

Map error when animating using LatLngBounds #11577

tan-tran-viet-xx opened this issue Mar 31, 2018 · 1 comment
Labels
Android Mapbox Maps SDK for Android

Comments

@tan-tran-viet-xx
Copy link

tan-tran-viet-xx commented Mar 31, 2018

Platform: Android + Kotlin
Mapbox SDK version: 5.5.1

Steps to trigger behavior

  1. Load map Async

  2. Create LatLngBounds with 2 locations:

    val startLatLng = LatLng(startingLocation.latitude,startingLocation.longitude)
    val endingLatLng = LatLng(endingLocation.latitude, endingLocation.longitude)
    mapboxMap.addMarker(MarkerOptions().position(startLatLng))
    mapboxMap.addMarker(MarkerOptions().position(endingLatLng))

    val latLngBounds = LatLngBounds.Builder()
        .include(startLatLng)
        .include(endingLatLng)
        .build()

    val cameraUpdate = CameraUpdateFactory.newLatLngBounds(latLngBounds,
        resources.getDimensionPixelSize(R.dimen.margin_padding_normal))
  1. Animate Camera

    mapboxMap.animateCamera(cameraUpdate, 1000)

Expected behavior

Map will be animated and zoomed to LatLngBounds

Actual behavior

Map error:
java.lang.NullPointerException: Attempt to read from field 'com.mapbox.mapboxsdk.geometry.LatLng com.mapbox.mapboxsdk.camera.CameraPosition.target' on a null object reference

@fabian-guerra fabian-guerra added the Android Mapbox Maps SDK for Android label Apr 2, 2018
@LukasPaczos
Copy link
Contributor

Thanks for reporting the issue @tan-tran-ea. CameraBoundsUpdate is the only update that doesn't invalidate camera before executing which results in said NPE, that's caught, but will escape the rest of the code block regardless.

Closing as the issue is already fixed with the upcoming 6.0.0, but I will add additional camera invalidation to the initialization process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

No branches or pull requests

3 participants