[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map Snapshots #86

Open
MobileAppsGO opened this issue Mar 31, 2022 · 20 comments
Open

Map Snapshots #86

MobileAppsGO opened this issue Mar 31, 2022 · 20 comments
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@MobileAppsGO
Copy link

Please add support for taking map snapshots:
GoogleMap::snapshot(@nonnull GoogleMap.SnapshotReadyCallback callback)

@MobileAppsGO MobileAppsGO added triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Mar 31, 2022
@jpoehnelt
Copy link
Contributor

@MobileAppsGO Thank you for opening this issue. 🙏
Please check out these other resources that might be applicable:

This is an automated message, feel free to ignore.

@recoverrelax
Copy link

I would also want this feature. Thanks!

@arriolac
Copy link
Member
arriolac commented May 18, 2022

Quickest is to expose a function in CameraPositionState although that won't to be the right place to do so. A state holder object like GoogleMapState that contains CameraPositionState etc. would be a better approach. Would be worth addressing that for the next major version change.

@barbeau barbeau added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed triage me I really want to be triaged. labels May 23, 2022
@recoverrelax
Copy link

any updates on this?

@arriolac
Copy link
Member
arriolac commented Aug 2, 2022

@recoverrelax you can use MapEffect to get the snapshot.

Something like:

GoogleMap {
   MapEffect { map ->
      map.snapshot { snapshot ->
         // Got snapshot here
      }
   }
}

@perdona
Copy link
perdona commented Oct 6, 2022

Is this going to be an official feature? It would be very nice to have a map span to base snapshot on, cause CameraPosition is very limited to handle multiple markers with a good framing displaying all markers.

@arriolac
Copy link
Member
arriolac commented Oct 6, 2022

Is this going to be an official feature? It would be very nice to have a map span to base snapshot on, cause CameraPosition is very limited to handle multiple markers with a good framing displaying all markers.

Can you clarify what you mean by 'It would be very nice to have a map span to base snapshot on'?

@perdona
Copy link
perdona commented Oct 6, 2022

Yes.. I think we should have other options of zoom, since in my case I need to frame multiple markers, and set the snapshot with a zoom that will show every marker wihtout being too far.

@pranandpatil
Copy link

Any update on this?
Is snapshot functionality is available ?

@petros-chariskos
Copy link

I have been using in production the recommend by @arriolac code snippet:

GoogleMap {
   MapEffect { map ->
      map.snapshot { snapshot ->
         // Got snapshot here
      }
   }
}

and is working. The downside is that in very rare cases and completely randomly it throws:

    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isMutable()' on a null object reference
    	at android.graphics.Canvas.<init>(Canvas.java:113)
    	at com.google.maps.api.android.lib6.impl.a.a(:com.google.android.gms.policy_maps_core_dynamite@233610103@233610101065.570495220.570495220:3)
    	at com.google.maps.api.android.lib6.phoenix.cb.run(:com.google.android.gms.policy_maps_core_dynamite@233610103@233610101065.570495220.570495220:9)
    	at android.os.Handler.handleCallback(Handler.java:958)
    	at android.os.Handler.dispatchMessage(Handler.java:99)
    	at android.os.Looper.loopOnce(Looper.java:205)
    	at android.os.Looper.loop(Looper.java:294)
    	at android.app.ActivityThread.main(ActivityThread.java:8194)
    	at java.lang.reflect.Method.invoke(Native Method)
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

maybe because MapEffect is still experimental? Will it be any update any time soon?

@easydev991
Copy link

We are still waiting for the stable official implementation, correct?

@alexandrupele
Copy link

@petros-chariskos i twas able to fix that NPE by putting that MapEffect behind a callback of "onMapLoaded". It's a parameter for GoogleMap. Try it, I hope it helps. I never seen the NPE ever since.

@petros-chariskos
Copy link

thank you @alexandrupele, I am already doing that and still getting the NPE. I can give the code snippet in case there is something wrong with my implementation but I think it's pretty straight forward.

var isMapLoaded by remember { mutableStateOf(false) }
val mapBitmap: MutableState<Bitmap?> = remember { mutableStateOf(null) }

GoogleMap(
    modifier = Modifier,
    cameraPositionState = cameraPositionState,
    properties = mapProperties,
    uiSettings = uiSettings,
    
        isMapLoaded = true
    }
) {
    MapMarker(
        context = LocalContext.current,
        state = rememberMarkerState(position = LatLng(latLng.latitude, latLng.longitude)),
        iconResourceId = iconResourceId
    )

    if (isMapLoaded) {
        MapEffect { map ->
            map.snapshot { snapshot ->
                mapBitmap.value = snapshot
            }
        }
    }
}

@JuanFranCrater
Copy link

Hi! Is this feature still being working on? Or any other way to access the googleMap instance without the use of MapEffect?Thanks!

@Badranh
Copy link
Badranh commented Feb 26, 2024

Would be awesome to have this feature +1

@alexandrupele
Copy link

@petros-chariskos try updating to compose maps 4.3.3. I see they've fixed a few things about the phase of the composition at which point the map is rendered. Let me know if it fixes it for you. I've also seen this crash again, now I'm hoping it goes away with the new version. I had 4.3.0 before.

@petros-chariskos
Copy link

Thanks @alexandrupele, I have updated the compose maps to 4.3.3 and this release is already in production since a couple of days ago. I hope this solves it, otherwise I will update the thread.

@petros-chariskos
Copy link

[Thread update] With com.google.maps.android:maps-compose in 4.3.3 the NPE: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isMutable()' on a null object reference still appears in the logs in production.

@alexandrupele
Copy link

I still get this crash. Anyone found a solution for it?

@alexandrupele
Copy link

@petros-chariskos check this thread until the end, i think the answer is there: https://issuetracker.google.com/issues/290806747

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests