Skip to content

Map initialization with desired configuration is delayed #491

Done

Description

@bubenheimer

Setting an initial camera position for the GoogleMap is commonly done by passing an appropriately initialized CameraPositionState parameter to the GoogleMap() Composable.

While reviewing the android-maps-compose code (4.3.0) I noticed that the GoogleMap camera is moved to its initial requested position (via CameraPositionState) only during the (sub-) composition apply phase. I believe this means that the entire initial sub-composition (short of applying) has to complete first. I think this could mean a significant delay in map position initialization, in particular if the sub-composition is fairly sizable.

Delaying map position initialization implies that loading tiles for the desired position is delayed. It would also mean additional visual artifacts, such as missing tiles and visually changing the map center from (0.0, 0.0) to the desired camera location.

From looking at the code I think it would be fairly easy and trouble-free to preempt the delay. The desired position is readily available before initializing the subcomposition and can be set right after awaitMap() has returned.

In terms of correctness, the parent composition would have completed at this point already, so the information from CameraPositionState can be considered valid/committed. I would expect that at this point the MapView would start being rendered, so the initial camera position should be set pronto.

Does this make sense? Looking for feedback.

private suspend inline fun MapView.newComposition(
parent: CompositionContext,
noinline content: @Composable () -> Unit
): Composition {
val map = awaitMap()
return Composition(
MapApplier(map, this), parent
).apply {
setContent(content)
}
}

LaunchedEffect(Unit) {
disposingComposition {
mapView.newComposition(parentComposition) {
MapUpdater(

Activity

  1. added
    triage me
    type: bug
    on Jan 1, 2024
  2. bubenheimer commented on Jan 4, 2024

    @bubenheimer
    ContributorAuthor

    The delay in setting initial CameraPosition was first introduced in 2237950. Up until then setting the camera was prompt.

    I see now that this problem is not just about the camera. There is other critical map configuration from MapProperties that is similarly delayed and could cause temporary visual artifacts, slowness, etc.: contentPadding and various MapProperties such as mapType.

    These additional concerns would likely require more substantial changes. Their introduction stems from the same commit.

  3. changed the title [-]Initial move to requested CameraPosition is delayed[/-] [+]Map initialization with desired configuration is delayed[/+] on Jan 4, 2024
  4. added
    priority: p3
    and removed
    triage me
    on Jan 4, 2024
  5. mishackee commented on Aug 14, 2024

    @mishackee

    Is there some workaround/update for this please? It makes maps in lazy lists quite unappealing.

  6. bubenheimer commented on Aug 14, 2024

    @bubenheimer
    ContributorAuthor

    @mishackee the concern I brought up in this issue is of a more theoretical and architectural nature, I have not quantified it.

    Reusing GoogleMap() inside a lazy list is optimized in current android-maps-compose releases to leverage ReusableComposition. As long as your code does not preclude reusing the GoogleMap() things should not be overly slow.

  7. mishackee commented on Aug 14, 2024

    @mishackee

    @bubenheimer Thanks for the prompt response. My bad, sorry, it seems to work in lazy lists once the map is initialized. However, adding it to the composition for the first time, the map is in some initial state and then jumps to my initial CameraPositionState. Is the delay configuration a possible cause of that? And if it is, is there a workaround for that now?

  8. bubenheimer commented on Aug 14, 2024

    @bubenheimer
    ContributorAuthor

    @mishackee thank you for adding this valuable detail. It is the type of behavior I would expect to see with this issue. However, a jump like that could also be caused by initializing CameraPositionState in a suboptimal manner. I am not aware of other reports of jumpy initialization behavior at this time. Can you post excerpts of your code showing how you initialize CameraPositionState and how you pass it into the GoogleMap()? There may be something else delaying CameraPositionState initialization to a later composition.

    As for a workaround, the problem should be more tolerable in R8/Proguard-optimized release builds, baseline profiles would likely help as well. See if this takes care of it.

  9. vijay-shingala commented on Oct 10, 2024

    @vijay-shingala

    @bubenheimer hey so I have been having this same issue where on initial load, the map flashes from latlong(0,0) to the request initial position. Wondering if there is a fix for this.

  10. RotBolt commented on Oct 5, 2026

    @RotBolt
    Contributor

    I'd like to take this issue.

    Proposed scope:

    • Apply the initial CameraPositionState.position to GoogleMapOptions before MapView creation.
    • Preserve a camera explicitly configured through googleMapOptionsFactory.
    • Keep subsequent camera updates on the existing CameraPositionState path.
    • Add regression tests covering both default and explicitly configured initial cameras.

    This follows the same initialization approach used for mapColorScheme in #976. Please confirm that the proposed precedence is correct before I start implementation.

  11. RotBolt commented on Oct 6, 2026

    @RotBolt
    Contributor

    I have raised the PR to fix this issue: #1027

  12. added a commit that references this issue on Oct 29, 2026
    9b4dd6d
  13. added a commit that references this issue on Nov 16, 2026
    fda0568
  14. added a commit that references this issue on Nov 24, 2026
    71ef9e7
  15. added a commit that references this issue on Nov 25, 2026
    d657239
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions