Skip to content

Google Maps Android compose 6.7.2 introduced NullPointerException: CameraUpdateFactory is not initialized #740

@outdoorapps

Description

@outdoorapps

The following setup was working in 6.7.1 but in 6.7.2, it throw NullPointerException on CameraUpdateFactory.newLatLngZoom

  1. Has this set up
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LocationBottomSheet(initialPosition: LatLng?) {
    var currentLocation by remember { mutableStateOf<Location?>(null) }
    val cameraState = rememberCameraPositionState {
        position = CameraPosition.fromLatLngZoom(initialPosition ?: LatLng(0.0, 0.0), 16f)
    }

    // Fetch location once on composition
    LaunchedEffect(currentLocation) {
        currentLocation?.let {
            cameraState.animate(
                update = CameraUpdateFactory.newLatLngZoom(
                    LatLng(it.latitude, it.longitude), 18f
                ),
                durationMs = 1000
            )
        }
    }
...
 GoogleMap(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(300.dp),
                cameraPositionState = cameraState,
  ...
}
  1. Run it and update = CameraUpdateFactory.newLatLngZoom throws NullPointerException

Stack trace

java.lang.NullPointerException: CameraUpdateFactory is not initialized
at com.google.android.gms.common.internal.Preconditions.checkNotNull(com.google.android.gms:play-services-basement@@18.5.0:2)
at com.google.android.gms.maps.CameraUpdateFactory.zzb(com.google.android.gms:play-services-maps@@19.2.0:1)
at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(com.google.android.gms:play-services-maps@@19.2.0:2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions